Upstream version 9.38.207.0
[platform/framework/web/crosswalk.git] / src / v8 / src / ia32 / assembler-ia32.cc
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.
35 // Copyright 2012 the V8 project authors. All rights reserved.
36
37 #include "src/v8.h"
38
39 #if V8_TARGET_ARCH_IA32
40
41 #include "src/base/cpu.h"
42 #include "src/disassembler.h"
43 #include "src/macro-assembler.h"
44 #include "src/serialize.h"
45
46 namespace v8 {
47 namespace internal {
48
49 // -----------------------------------------------------------------------------
50 // Implementation of CpuFeatures
51
52 void CpuFeatures::ProbeImpl(bool cross_compile) {
53   base::CPU cpu;
54   CHECK(cpu.has_sse2());  // SSE2 support is mandatory.
55   CHECK(cpu.has_cmov());  // CMOV support is mandatory.
56
57   // Only use statically determined features for cross compile (snapshot).
58   if (cross_compile) return;
59
60   if (cpu.has_sse41() && FLAG_enable_sse4_1) supported_ |= 1u << SSE4_1;
61   if (cpu.has_sse3() && FLAG_enable_sse3) supported_ |= 1u << SSE3;
62 }
63
64
65 void CpuFeatures::PrintTarget() { }
66 void CpuFeatures::PrintFeatures() { }
67
68
69 // -----------------------------------------------------------------------------
70 // Implementation of Displacement
71
72 void Displacement::init(Label* L, Type type) {
73   DCHECK(!L->is_bound());
74   int next = 0;
75   if (L->is_linked()) {
76     next = L->pos();
77     DCHECK(next > 0);  // Displacements must be at positions > 0
78   }
79   // Ensure that we _never_ overflow the next field.
80   DCHECK(NextField::is_valid(Assembler::kMaximalBufferSize));
81   data_ = NextField::encode(next) | TypeField::encode(type);
82 }
83
84
85 // -----------------------------------------------------------------------------
86 // Implementation of RelocInfo
87
88
89 const int RelocInfo::kApplyMask =
90   RelocInfo::kCodeTargetMask | 1 << RelocInfo::RUNTIME_ENTRY |
91     1 << RelocInfo::JS_RETURN | 1 << RelocInfo::INTERNAL_REFERENCE |
92     1 << RelocInfo::DEBUG_BREAK_SLOT | 1 << RelocInfo::CODE_AGE_SEQUENCE;
93
94
95 bool RelocInfo::IsCodedSpecially() {
96   // The deserializer needs to know whether a pointer is specially coded.  Being
97   // specially coded on IA32 means that it is a relative address, as used by
98   // branch instructions.  These are also the ones that need changing when a
99   // code object moves.
100   return (1 << rmode_) & kApplyMask;
101 }
102
103
104 bool RelocInfo::IsInConstantPool() {
105   return false;
106 }
107
108
109 void RelocInfo::PatchCode(byte* instructions, int instruction_count) {
110   // Patch the code at the current address with the supplied instructions.
111   for (int i = 0; i < instruction_count; i++) {
112     *(pc_ + i) = *(instructions + i);
113   }
114
115   // Indicate that code has changed.
116   CpuFeatures::FlushICache(pc_, instruction_count);
117 }
118
119
120 // Patch the code at the current PC with a call to the target address.
121 // Additional guard int3 instructions can be added if required.
122 void RelocInfo::PatchCodeWithCall(Address target, int guard_bytes) {
123   // Call instruction takes up 5 bytes and int3 takes up one byte.
124   static const int kCallCodeSize = 5;
125   int code_size = kCallCodeSize + guard_bytes;
126
127   // Create a code patcher.
128   CodePatcher patcher(pc_, code_size);
129
130   // Add a label for checking the size of the code used for returning.
131 #ifdef DEBUG
132   Label check_codesize;
133   patcher.masm()->bind(&check_codesize);
134 #endif
135
136   // Patch the code.
137   patcher.masm()->call(target, RelocInfo::NONE32);
138
139   // Check that the size of the code generated is as expected.
140   DCHECK_EQ(kCallCodeSize,
141             patcher.masm()->SizeOfCodeGeneratedSince(&check_codesize));
142
143   // Add the requested number of int3 instructions after the call.
144   DCHECK_GE(guard_bytes, 0);
145   for (int i = 0; i < guard_bytes; i++) {
146     patcher.masm()->int3();
147   }
148 }
149
150
151 // -----------------------------------------------------------------------------
152 // Implementation of Operand
153
154 Operand::Operand(Register base, int32_t disp, RelocInfo::Mode rmode) {
155   // [base + disp/r]
156   if (disp == 0 && RelocInfo::IsNone(rmode) && !base.is(ebp)) {
157     // [base]
158     set_modrm(0, base);
159     if (base.is(esp)) set_sib(times_1, esp, base);
160   } else if (is_int8(disp) && RelocInfo::IsNone(rmode)) {
161     // [base + disp8]
162     set_modrm(1, base);
163     if (base.is(esp)) set_sib(times_1, esp, base);
164     set_disp8(disp);
165   } else {
166     // [base + disp/r]
167     set_modrm(2, base);
168     if (base.is(esp)) set_sib(times_1, esp, base);
169     set_dispr(disp, rmode);
170   }
171 }
172
173
174 Operand::Operand(Register base,
175                  Register index,
176                  ScaleFactor scale,
177                  int32_t disp,
178                  RelocInfo::Mode rmode) {
179   DCHECK(!index.is(esp));  // illegal addressing mode
180   // [base + index*scale + disp/r]
181   if (disp == 0 && RelocInfo::IsNone(rmode) && !base.is(ebp)) {
182     // [base + index*scale]
183     set_modrm(0, esp);
184     set_sib(scale, index, base);
185   } else if (is_int8(disp) && RelocInfo::IsNone(rmode)) {
186     // [base + index*scale + disp8]
187     set_modrm(1, esp);
188     set_sib(scale, index, base);
189     set_disp8(disp);
190   } else {
191     // [base + index*scale + disp/r]
192     set_modrm(2, esp);
193     set_sib(scale, index, base);
194     set_dispr(disp, rmode);
195   }
196 }
197
198
199 Operand::Operand(Register index,
200                  ScaleFactor scale,
201                  int32_t disp,
202                  RelocInfo::Mode rmode) {
203   DCHECK(!index.is(esp));  // illegal addressing mode
204   // [index*scale + disp/r]
205   set_modrm(0, esp);
206   set_sib(scale, index, ebp);
207   set_dispr(disp, rmode);
208 }
209
210
211 Operand::Operand(const Operand& operand, int32_t offset) {
212   DCHECK(operand.len_ >= 1);
213   // Operand encodes REX ModR/M [SIB] [Disp].
214   byte modrm = operand.buf_[0];
215   DCHECK(modrm < 0xC0);  // Disallow mode 3 (register target).
216   bool has_sib = ((modrm & 0x07) == 0x04);
217   byte mode = modrm & 0xC0;
218   int disp_offset = has_sib ? 2 : 1;
219   int base_reg = (has_sib ? operand.buf_[1] : modrm) & 0x07;
220   // Mode 0 with rbp/r13 as ModR/M or SIB base register always has a 32-bit
221   // displacement.
222   bool is_baseless = (mode == 0) && (base_reg == 0x05);  // No base or RIP base.
223   int32_t disp_value = 0;
224   if (mode == 0x80 || is_baseless) {
225     // Mode 2 or mode 0 with rbp/r13 as base: Word displacement.
226     disp_value = *BitCast<const int32_t*>(&operand.buf_[disp_offset]);
227   } else if (mode == 0x40) {
228     // Mode 1: Byte displacement.
229     disp_value = static_cast<signed char>(operand.buf_[disp_offset]);
230   }
231
232   // Write new operand with same registers, but with modified displacement.
233   DCHECK(offset >= 0 ? disp_value + offset >= disp_value
234                      : disp_value + offset < disp_value);  // No overflow.
235   disp_value += offset;
236   if (!is_int8(disp_value) || is_baseless) {
237     // Need 32 bits of displacement, mode 2 or mode 1 with register rbp/r13.
238     buf_[0] = (modrm & 0x3f) | (is_baseless ? 0x00 : 0x80);
239     len_ = disp_offset + 4;
240     Memory::int32_at(&buf_[disp_offset]) = disp_value;
241   } else if (disp_value != 0 || (base_reg == 0x05)) {
242     // Need 8 bits of displacement.
243     buf_[0] = (modrm & 0x3f) | 0x40;  // Mode 1.
244     len_ = disp_offset + 1;
245     buf_[disp_offset] = static_cast<byte>(disp_value);
246   } else {
247     // Need no displacement.
248     buf_[0] = (modrm & 0x3f);  // Mode 0.
249     len_ = disp_offset;
250   }
251   if (has_sib) {
252     buf_[1] = operand.buf_[1];
253   }
254 }
255
256
257 bool Operand::is_reg(Register reg) const {
258   return ((buf_[0] & 0xF8) == 0xC0)  // addressing mode is register only.
259       && ((buf_[0] & 0x07) == reg.code());  // register codes match.
260 }
261
262
263 bool Operand::is_reg_only() const {
264   return (buf_[0] & 0xF8) == 0xC0;  // Addressing mode is register only.
265 }
266
267
268 Register Operand::reg() const {
269   DCHECK(is_reg_only());
270   return Register::from_code(buf_[0] & 0x07);
271 }
272
273
274 // -----------------------------------------------------------------------------
275 // Implementation of Assembler.
276
277 // Emit a single byte. Must always be inlined.
278 #define EMIT(x)                                 \
279   *pc_++ = (x)
280
281
282 #ifdef GENERATED_CODE_COVERAGE
283 static void InitCoverageLog();
284 #endif
285
286 Assembler::Assembler(Isolate* isolate, void* buffer, int buffer_size)
287     : AssemblerBase(isolate, buffer, buffer_size),
288       positions_recorder_(this) {
289   // Clear the buffer in debug mode unless it was provided by the
290   // caller in which case we can't be sure it's okay to overwrite
291   // existing code in it; see CodePatcher::CodePatcher(...).
292 #ifdef DEBUG
293   if (own_buffer_) {
294     memset(buffer_, 0xCC, buffer_size_);  // int3
295   }
296 #endif
297
298   reloc_info_writer.Reposition(buffer_ + buffer_size_, pc_);
299
300 #ifdef GENERATED_CODE_COVERAGE
301   InitCoverageLog();
302 #endif
303 }
304
305
306 void Assembler::GetCode(CodeDesc* desc) {
307   // Finalize code (at this point overflow() may be true, but the gap ensures
308   // that we are still not overlapping instructions and relocation info).
309   DCHECK(pc_ <= reloc_info_writer.pos());  // No overlap.
310   // Set up code descriptor.
311   desc->buffer = buffer_;
312   desc->buffer_size = buffer_size_;
313   desc->instr_size = pc_offset();
314   desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos();
315   desc->origin = this;
316 }
317
318
319 void Assembler::Align(int m) {
320   DCHECK(IsPowerOf2(m));
321   int mask = m - 1;
322   int addr = pc_offset();
323   Nop((m - (addr & mask)) & mask);
324 }
325
326
327 bool Assembler::IsNop(Address addr) {
328   Address a = addr;
329   while (*a == 0x66) a++;
330   if (*a == 0x90) return true;
331   if (a[0] == 0xf && a[1] == 0x1f) return true;
332   return false;
333 }
334
335
336 void Assembler::Nop(int bytes) {
337   EnsureSpace ensure_space(this);
338
339   // Multi byte nops from http://support.amd.com/us/Processor_TechDocs/40546.pdf
340   while (bytes > 0) {
341     switch (bytes) {
342       case 2:
343         EMIT(0x66);
344       case 1:
345         EMIT(0x90);
346         return;
347       case 3:
348         EMIT(0xf);
349         EMIT(0x1f);
350         EMIT(0);
351         return;
352       case 4:
353         EMIT(0xf);
354         EMIT(0x1f);
355         EMIT(0x40);
356         EMIT(0);
357         return;
358       case 6:
359         EMIT(0x66);
360       case 5:
361         EMIT(0xf);
362         EMIT(0x1f);
363         EMIT(0x44);
364         EMIT(0);
365         EMIT(0);
366         return;
367       case 7:
368         EMIT(0xf);
369         EMIT(0x1f);
370         EMIT(0x80);
371         EMIT(0);
372         EMIT(0);
373         EMIT(0);
374         EMIT(0);
375         return;
376       default:
377       case 11:
378         EMIT(0x66);
379         bytes--;
380       case 10:
381         EMIT(0x66);
382         bytes--;
383       case 9:
384         EMIT(0x66);
385         bytes--;
386       case 8:
387         EMIT(0xf);
388         EMIT(0x1f);
389         EMIT(0x84);
390         EMIT(0);
391         EMIT(0);
392         EMIT(0);
393         EMIT(0);
394         EMIT(0);
395         bytes -= 8;
396     }
397   }
398 }
399
400
401 void Assembler::CodeTargetAlign() {
402   Align(16);  // Preferred alignment of jump targets on ia32.
403 }
404
405
406 void Assembler::cpuid() {
407   EnsureSpace ensure_space(this);
408   EMIT(0x0F);
409   EMIT(0xA2);
410 }
411
412
413 void Assembler::pushad() {
414   EnsureSpace ensure_space(this);
415   EMIT(0x60);
416 }
417
418
419 void Assembler::popad() {
420   EnsureSpace ensure_space(this);
421   EMIT(0x61);
422 }
423
424
425 void Assembler::pushfd() {
426   EnsureSpace ensure_space(this);
427   EMIT(0x9C);
428 }
429
430
431 void Assembler::popfd() {
432   EnsureSpace ensure_space(this);
433   EMIT(0x9D);
434 }
435
436
437 void Assembler::push(const Immediate& x) {
438   EnsureSpace ensure_space(this);
439   if (x.is_int8()) {
440     EMIT(0x6a);
441     EMIT(x.x_);
442   } else {
443     EMIT(0x68);
444     emit(x);
445   }
446 }
447
448
449 void Assembler::push_imm32(int32_t imm32) {
450   EnsureSpace ensure_space(this);
451   EMIT(0x68);
452   emit(imm32);
453 }
454
455
456 void Assembler::push(Register src) {
457   EnsureSpace ensure_space(this);
458   EMIT(0x50 | src.code());
459 }
460
461
462 void Assembler::push(const Operand& src) {
463   EnsureSpace ensure_space(this);
464   EMIT(0xFF);
465   emit_operand(esi, src);
466 }
467
468
469 void Assembler::pop(Register dst) {
470   DCHECK(reloc_info_writer.last_pc() != NULL);
471   EnsureSpace ensure_space(this);
472   EMIT(0x58 | dst.code());
473 }
474
475
476 void Assembler::pop(const Operand& dst) {
477   EnsureSpace ensure_space(this);
478   EMIT(0x8F);
479   emit_operand(eax, dst);
480 }
481
482
483 void Assembler::enter(const Immediate& size) {
484   EnsureSpace ensure_space(this);
485   EMIT(0xC8);
486   emit_w(size);
487   EMIT(0);
488 }
489
490
491 void Assembler::leave() {
492   EnsureSpace ensure_space(this);
493   EMIT(0xC9);
494 }
495
496
497 void Assembler::mov_b(Register dst, const Operand& src) {
498   CHECK(dst.is_byte_register());
499   EnsureSpace ensure_space(this);
500   EMIT(0x8A);
501   emit_operand(dst, src);
502 }
503
504
505 void Assembler::mov_b(const Operand& dst, int8_t imm8) {
506   EnsureSpace ensure_space(this);
507   EMIT(0xC6);
508   emit_operand(eax, dst);
509   EMIT(imm8);
510 }
511
512
513 void Assembler::mov_b(const Operand& dst, Register src) {
514   CHECK(src.is_byte_register());
515   EnsureSpace ensure_space(this);
516   EMIT(0x88);
517   emit_operand(src, dst);
518 }
519
520
521 void Assembler::mov_w(Register dst, const Operand& src) {
522   EnsureSpace ensure_space(this);
523   EMIT(0x66);
524   EMIT(0x8B);
525   emit_operand(dst, src);
526 }
527
528
529 void Assembler::mov_w(const Operand& dst, Register src) {
530   EnsureSpace ensure_space(this);
531   EMIT(0x66);
532   EMIT(0x89);
533   emit_operand(src, dst);
534 }
535
536
537 void Assembler::mov_w(const Operand& dst, int16_t imm16) {
538   EnsureSpace ensure_space(this);
539   EMIT(0x66);
540   EMIT(0xC7);
541   emit_operand(eax, dst);
542   EMIT(static_cast<int8_t>(imm16 & 0xff));
543   EMIT(static_cast<int8_t>(imm16 >> 8));
544 }
545
546
547 void Assembler::mov(Register dst, int32_t imm32) {
548   EnsureSpace ensure_space(this);
549   EMIT(0xB8 | dst.code());
550   emit(imm32);
551 }
552
553
554 void Assembler::mov(Register dst, const Immediate& x) {
555   EnsureSpace ensure_space(this);
556   EMIT(0xB8 | dst.code());
557   emit(x);
558 }
559
560
561 void Assembler::mov(Register dst, Handle<Object> handle) {
562   EnsureSpace ensure_space(this);
563   EMIT(0xB8 | dst.code());
564   emit(handle);
565 }
566
567
568 void Assembler::mov(Register dst, const Operand& src) {
569   EnsureSpace ensure_space(this);
570   EMIT(0x8B);
571   emit_operand(dst, src);
572 }
573
574
575 void Assembler::mov(Register dst, Register src) {
576   EnsureSpace ensure_space(this);
577   EMIT(0x89);
578   EMIT(0xC0 | src.code() << 3 | dst.code());
579 }
580
581
582 void Assembler::mov(const Operand& dst, const Immediate& x) {
583   EnsureSpace ensure_space(this);
584   EMIT(0xC7);
585   emit_operand(eax, dst);
586   emit(x);
587 }
588
589
590 void Assembler::mov(const Operand& dst, Handle<Object> handle) {
591   EnsureSpace ensure_space(this);
592   EMIT(0xC7);
593   emit_operand(eax, dst);
594   emit(handle);
595 }
596
597
598 void Assembler::mov(const Operand& dst, Register src) {
599   EnsureSpace ensure_space(this);
600   EMIT(0x89);
601   emit_operand(src, dst);
602 }
603
604
605 void Assembler::movsx_b(Register dst, const Operand& src) {
606   EnsureSpace ensure_space(this);
607   EMIT(0x0F);
608   EMIT(0xBE);
609   emit_operand(dst, src);
610 }
611
612
613 void Assembler::movsx_w(Register dst, const Operand& src) {
614   EnsureSpace ensure_space(this);
615   EMIT(0x0F);
616   EMIT(0xBF);
617   emit_operand(dst, src);
618 }
619
620
621 void Assembler::movzx_b(Register dst, const Operand& src) {
622   EnsureSpace ensure_space(this);
623   EMIT(0x0F);
624   EMIT(0xB6);
625   emit_operand(dst, src);
626 }
627
628
629 void Assembler::movzx_w(Register dst, const Operand& src) {
630   EnsureSpace ensure_space(this);
631   EMIT(0x0F);
632   EMIT(0xB7);
633   emit_operand(dst, src);
634 }
635
636
637 void Assembler::cmov(Condition cc, Register dst, const Operand& src) {
638   EnsureSpace ensure_space(this);
639   // Opcode: 0f 40 + cc /r.
640   EMIT(0x0F);
641   EMIT(0x40 + cc);
642   emit_operand(dst, src);
643 }
644
645
646 void Assembler::cld() {
647   EnsureSpace ensure_space(this);
648   EMIT(0xFC);
649 }
650
651
652 void Assembler::rep_movs() {
653   EnsureSpace ensure_space(this);
654   EMIT(0xF3);
655   EMIT(0xA5);
656 }
657
658
659 void Assembler::rep_stos() {
660   EnsureSpace ensure_space(this);
661   EMIT(0xF3);
662   EMIT(0xAB);
663 }
664
665
666 void Assembler::stos() {
667   EnsureSpace ensure_space(this);
668   EMIT(0xAB);
669 }
670
671
672 void Assembler::xchg(Register dst, Register src) {
673   EnsureSpace ensure_space(this);
674   if (src.is(eax) || dst.is(eax)) {  // Single-byte encoding.
675     EMIT(0x90 | (src.is(eax) ? dst.code() : src.code()));
676   } else {
677     EMIT(0x87);
678     EMIT(0xC0 | src.code() << 3 | dst.code());
679   }
680 }
681
682
683 void Assembler::xchg(Register dst, const Operand& src) {
684   EnsureSpace ensure_space(this);
685   EMIT(0x87);
686   emit_operand(dst, src);
687 }
688
689
690 void Assembler::adc(Register dst, int32_t imm32) {
691   EnsureSpace ensure_space(this);
692   emit_arith(2, Operand(dst), Immediate(imm32));
693 }
694
695
696 void Assembler::adc(Register dst, const Operand& src) {
697   EnsureSpace ensure_space(this);
698   EMIT(0x13);
699   emit_operand(dst, src);
700 }
701
702
703 void Assembler::add(Register dst, const Operand& src) {
704   EnsureSpace ensure_space(this);
705   EMIT(0x03);
706   emit_operand(dst, src);
707 }
708
709
710 void Assembler::add(const Operand& dst, Register src) {
711   EnsureSpace ensure_space(this);
712   EMIT(0x01);
713   emit_operand(src, dst);
714 }
715
716
717 void Assembler::add(const Operand& dst, const Immediate& x) {
718   DCHECK(reloc_info_writer.last_pc() != NULL);
719   EnsureSpace ensure_space(this);
720   emit_arith(0, dst, x);
721 }
722
723
724 void Assembler::and_(Register dst, int32_t imm32) {
725   and_(dst, Immediate(imm32));
726 }
727
728
729 void Assembler::and_(Register dst, const Immediate& x) {
730   EnsureSpace ensure_space(this);
731   emit_arith(4, Operand(dst), x);
732 }
733
734
735 void Assembler::and_(Register dst, const Operand& src) {
736   EnsureSpace ensure_space(this);
737   EMIT(0x23);
738   emit_operand(dst, src);
739 }
740
741
742 void Assembler::and_(const Operand& dst, const Immediate& x) {
743   EnsureSpace ensure_space(this);
744   emit_arith(4, dst, x);
745 }
746
747
748 void Assembler::and_(const Operand& dst, Register src) {
749   EnsureSpace ensure_space(this);
750   EMIT(0x21);
751   emit_operand(src, dst);
752 }
753
754
755 void Assembler::cmpb(const Operand& op, int8_t imm8) {
756   EnsureSpace ensure_space(this);
757   if (op.is_reg(eax)) {
758     EMIT(0x3C);
759   } else {
760     EMIT(0x80);
761     emit_operand(edi, op);  // edi == 7
762   }
763   EMIT(imm8);
764 }
765
766
767 void Assembler::cmpb(const Operand& op, Register reg) {
768   CHECK(reg.is_byte_register());
769   EnsureSpace ensure_space(this);
770   EMIT(0x38);
771   emit_operand(reg, op);
772 }
773
774
775 void Assembler::cmpb(Register reg, const Operand& op) {
776   CHECK(reg.is_byte_register());
777   EnsureSpace ensure_space(this);
778   EMIT(0x3A);
779   emit_operand(reg, op);
780 }
781
782
783 void Assembler::cmpw(const Operand& op, Immediate imm16) {
784   DCHECK(imm16.is_int16());
785   EnsureSpace ensure_space(this);
786   EMIT(0x66);
787   EMIT(0x81);
788   emit_operand(edi, op);
789   emit_w(imm16);
790 }
791
792
793 void Assembler::cmp(Register reg, int32_t imm32) {
794   EnsureSpace ensure_space(this);
795   emit_arith(7, Operand(reg), Immediate(imm32));
796 }
797
798
799 void Assembler::cmp(Register reg, Handle<Object> handle) {
800   EnsureSpace ensure_space(this);
801   emit_arith(7, Operand(reg), Immediate(handle));
802 }
803
804
805 void Assembler::cmp(Register reg, const Operand& op) {
806   EnsureSpace ensure_space(this);
807   EMIT(0x3B);
808   emit_operand(reg, op);
809 }
810
811
812 void Assembler::cmp(const Operand& op, const Immediate& imm) {
813   EnsureSpace ensure_space(this);
814   emit_arith(7, op, imm);
815 }
816
817
818 void Assembler::cmp(const Operand& op, Handle<Object> handle) {
819   EnsureSpace ensure_space(this);
820   emit_arith(7, op, Immediate(handle));
821 }
822
823
824 void Assembler::cmpb_al(const Operand& op) {
825   EnsureSpace ensure_space(this);
826   EMIT(0x38);  // CMP r/m8, r8
827   emit_operand(eax, op);  // eax has same code as register al.
828 }
829
830
831 void Assembler::cmpw_ax(const Operand& op) {
832   EnsureSpace ensure_space(this);
833   EMIT(0x66);
834   EMIT(0x39);  // CMP r/m16, r16
835   emit_operand(eax, op);  // eax has same code as register ax.
836 }
837
838
839 void Assembler::dec_b(Register dst) {
840   CHECK(dst.is_byte_register());
841   EnsureSpace ensure_space(this);
842   EMIT(0xFE);
843   EMIT(0xC8 | dst.code());
844 }
845
846
847 void Assembler::dec_b(const Operand& dst) {
848   EnsureSpace ensure_space(this);
849   EMIT(0xFE);
850   emit_operand(ecx, dst);
851 }
852
853
854 void Assembler::dec(Register dst) {
855   EnsureSpace ensure_space(this);
856   EMIT(0x48 | dst.code());
857 }
858
859
860 void Assembler::dec(const Operand& dst) {
861   EnsureSpace ensure_space(this);
862   EMIT(0xFF);
863   emit_operand(ecx, dst);
864 }
865
866
867 void Assembler::cdq() {
868   EnsureSpace ensure_space(this);
869   EMIT(0x99);
870 }
871
872
873 void Assembler::idiv(const Operand& src) {
874   EnsureSpace ensure_space(this);
875   EMIT(0xF7);
876   emit_operand(edi, src);
877 }
878
879
880 void Assembler::div(const Operand& src) {
881   EnsureSpace ensure_space(this);
882   EMIT(0xF7);
883   emit_operand(esi, src);
884 }
885
886
887 void Assembler::imul(Register reg) {
888   EnsureSpace ensure_space(this);
889   EMIT(0xF7);
890   EMIT(0xE8 | reg.code());
891 }
892
893
894 void Assembler::imul(Register dst, const Operand& src) {
895   EnsureSpace ensure_space(this);
896   EMIT(0x0F);
897   EMIT(0xAF);
898   emit_operand(dst, src);
899 }
900
901
902 void Assembler::imul(Register dst, Register src, int32_t imm32) {
903   imul(dst, Operand(src), imm32);
904 }
905
906
907 void Assembler::imul(Register dst, const Operand& src, int32_t imm32) {
908   EnsureSpace ensure_space(this);
909   if (is_int8(imm32)) {
910     EMIT(0x6B);
911     emit_operand(dst, src);
912     EMIT(imm32);
913   } else {
914     EMIT(0x69);
915     emit_operand(dst, src);
916     emit(imm32);
917   }
918 }
919
920
921 void Assembler::inc(Register dst) {
922   EnsureSpace ensure_space(this);
923   EMIT(0x40 | dst.code());
924 }
925
926
927 void Assembler::inc(const Operand& dst) {
928   EnsureSpace ensure_space(this);
929   EMIT(0xFF);
930   emit_operand(eax, dst);
931 }
932
933
934 void Assembler::lea(Register dst, const Operand& src) {
935   EnsureSpace ensure_space(this);
936   EMIT(0x8D);
937   emit_operand(dst, src);
938 }
939
940
941 void Assembler::mul(Register src) {
942   EnsureSpace ensure_space(this);
943   EMIT(0xF7);
944   EMIT(0xE0 | src.code());
945 }
946
947
948 void Assembler::neg(Register dst) {
949   EnsureSpace ensure_space(this);
950   EMIT(0xF7);
951   EMIT(0xD8 | dst.code());
952 }
953
954
955 void Assembler::neg(const Operand& dst) {
956   EnsureSpace ensure_space(this);
957   EMIT(0xF7);
958   emit_operand(ebx, dst);
959 }
960
961
962 void Assembler::not_(Register dst) {
963   EnsureSpace ensure_space(this);
964   EMIT(0xF7);
965   EMIT(0xD0 | dst.code());
966 }
967
968
969 void Assembler::not_(const Operand& dst) {
970   EnsureSpace ensure_space(this);
971   EMIT(0xF7);
972   emit_operand(edx, dst);
973 }
974
975
976 void Assembler::or_(Register dst, int32_t imm32) {
977   EnsureSpace ensure_space(this);
978   emit_arith(1, Operand(dst), Immediate(imm32));
979 }
980
981
982 void Assembler::or_(Register dst, const Operand& src) {
983   EnsureSpace ensure_space(this);
984   EMIT(0x0B);
985   emit_operand(dst, src);
986 }
987
988
989 void Assembler::or_(const Operand& dst, const Immediate& x) {
990   EnsureSpace ensure_space(this);
991   emit_arith(1, dst, x);
992 }
993
994
995 void Assembler::or_(const Operand& dst, Register src) {
996   EnsureSpace ensure_space(this);
997   EMIT(0x09);
998   emit_operand(src, dst);
999 }
1000
1001
1002 void Assembler::rcl(Register dst, uint8_t imm8) {
1003   EnsureSpace ensure_space(this);
1004   DCHECK(is_uint5(imm8));  // illegal shift count
1005   if (imm8 == 1) {
1006     EMIT(0xD1);
1007     EMIT(0xD0 | dst.code());
1008   } else {
1009     EMIT(0xC1);
1010     EMIT(0xD0 | dst.code());
1011     EMIT(imm8);
1012   }
1013 }
1014
1015
1016 void Assembler::rcr(Register dst, uint8_t imm8) {
1017   EnsureSpace ensure_space(this);
1018   DCHECK(is_uint5(imm8));  // illegal shift count
1019   if (imm8 == 1) {
1020     EMIT(0xD1);
1021     EMIT(0xD8 | dst.code());
1022   } else {
1023     EMIT(0xC1);
1024     EMIT(0xD8 | dst.code());
1025     EMIT(imm8);
1026   }
1027 }
1028
1029
1030 void Assembler::ror(Register dst, uint8_t imm8) {
1031   EnsureSpace ensure_space(this);
1032   DCHECK(is_uint5(imm8));  // illegal shift count
1033   if (imm8 == 1) {
1034     EMIT(0xD1);
1035     EMIT(0xC8 | dst.code());
1036   } else {
1037     EMIT(0xC1);
1038     EMIT(0xC8 | dst.code());
1039     EMIT(imm8);
1040   }
1041 }
1042
1043
1044 void Assembler::ror_cl(Register dst) {
1045   EnsureSpace ensure_space(this);
1046   EMIT(0xD3);
1047   EMIT(0xC8 | dst.code());
1048 }
1049
1050
1051 void Assembler::sar(const Operand& dst, uint8_t imm8) {
1052   EnsureSpace ensure_space(this);
1053   DCHECK(is_uint5(imm8));  // illegal shift count
1054   if (imm8 == 1) {
1055     EMIT(0xD1);
1056     emit_operand(edi, dst);
1057   } else {
1058     EMIT(0xC1);
1059     emit_operand(edi, dst);
1060     EMIT(imm8);
1061   }
1062 }
1063
1064
1065 void Assembler::sar_cl(const Operand& dst) {
1066   EnsureSpace ensure_space(this);
1067   EMIT(0xD3);
1068   emit_operand(edi, dst);
1069 }
1070
1071
1072 void Assembler::sbb(Register dst, const Operand& src) {
1073   EnsureSpace ensure_space(this);
1074   EMIT(0x1B);
1075   emit_operand(dst, src);
1076 }
1077
1078
1079 void Assembler::shld(Register dst, const Operand& src) {
1080   EnsureSpace ensure_space(this);
1081   EMIT(0x0F);
1082   EMIT(0xA5);
1083   emit_operand(dst, src);
1084 }
1085
1086
1087 void Assembler::shl(const Operand& dst, uint8_t imm8) {
1088   EnsureSpace ensure_space(this);
1089   DCHECK(is_uint5(imm8));  // illegal shift count
1090   if (imm8 == 1) {
1091     EMIT(0xD1);
1092     emit_operand(esp, dst);
1093   } else {
1094     EMIT(0xC1);
1095     emit_operand(esp, dst);
1096     EMIT(imm8);
1097   }
1098 }
1099
1100
1101 void Assembler::shl_cl(const Operand& dst) {
1102   EnsureSpace ensure_space(this);
1103   EMIT(0xD3);
1104   emit_operand(esp, dst);
1105 }
1106
1107
1108 void Assembler::shrd(Register dst, const Operand& src) {
1109   EnsureSpace ensure_space(this);
1110   EMIT(0x0F);
1111   EMIT(0xAD);
1112   emit_operand(dst, src);
1113 }
1114
1115
1116 void Assembler::shr(const Operand& dst, uint8_t imm8) {
1117   EnsureSpace ensure_space(this);
1118   DCHECK(is_uint5(imm8));  // illegal shift count
1119   if (imm8 == 1) {
1120     EMIT(0xD1);
1121     emit_operand(ebp, dst);
1122   } else {
1123     EMIT(0xC1);
1124     emit_operand(ebp, dst);
1125     EMIT(imm8);
1126   }
1127 }
1128
1129
1130 void Assembler::shr_cl(const Operand& dst) {
1131   EnsureSpace ensure_space(this);
1132   EMIT(0xD3);
1133   emit_operand(ebp, dst);
1134 }
1135
1136
1137 void Assembler::sub(const Operand& dst, const Immediate& x) {
1138   EnsureSpace ensure_space(this);
1139   emit_arith(5, dst, x);
1140 }
1141
1142
1143 void Assembler::sub(Register dst, const Operand& src) {
1144   EnsureSpace ensure_space(this);
1145   EMIT(0x2B);
1146   emit_operand(dst, src);
1147 }
1148
1149
1150 void Assembler::sub(const Operand& dst, Register src) {
1151   EnsureSpace ensure_space(this);
1152   EMIT(0x29);
1153   emit_operand(src, dst);
1154 }
1155
1156
1157 void Assembler::test(Register reg, const Immediate& imm) {
1158   if (RelocInfo::IsNone(imm.rmode_) && is_uint8(imm.x_)) {
1159     test_b(reg, imm.x_);
1160     return;
1161   }
1162
1163   EnsureSpace ensure_space(this);
1164   // This is not using emit_arith because test doesn't support
1165   // sign-extension of 8-bit operands.
1166   if (reg.is(eax)) {
1167     EMIT(0xA9);
1168   } else {
1169     EMIT(0xF7);
1170     EMIT(0xC0 | reg.code());
1171   }
1172   emit(imm);
1173 }
1174
1175
1176 void Assembler::test(Register reg, const Operand& op) {
1177   EnsureSpace ensure_space(this);
1178   EMIT(0x85);
1179   emit_operand(reg, op);
1180 }
1181
1182
1183 void Assembler::test_b(Register reg, const Operand& op) {
1184   CHECK(reg.is_byte_register());
1185   EnsureSpace ensure_space(this);
1186   EMIT(0x84);
1187   emit_operand(reg, op);
1188 }
1189
1190
1191 void Assembler::test(const Operand& op, const Immediate& imm) {
1192   if (op.is_reg_only()) {
1193     test(op.reg(), imm);
1194     return;
1195   }
1196   if (RelocInfo::IsNone(imm.rmode_) && is_uint8(imm.x_)) {
1197     return test_b(op, imm.x_);
1198   }
1199   EnsureSpace ensure_space(this);
1200   EMIT(0xF7);
1201   emit_operand(eax, op);
1202   emit(imm);
1203 }
1204
1205
1206 void Assembler::test_b(Register reg, uint8_t imm8) {
1207   EnsureSpace ensure_space(this);
1208   // Only use test against byte for registers that have a byte
1209   // variant: eax, ebx, ecx, and edx.
1210   if (reg.is(eax)) {
1211     EMIT(0xA8);
1212     EMIT(imm8);
1213   } else if (reg.is_byte_register()) {
1214     emit_arith_b(0xF6, 0xC0, reg, imm8);
1215   } else {
1216     EMIT(0xF7);
1217     EMIT(0xC0 | reg.code());
1218     emit(imm8);
1219   }
1220 }
1221
1222
1223 void Assembler::test_b(const Operand& op, uint8_t imm8) {
1224   if (op.is_reg_only()) {
1225     test_b(op.reg(), imm8);
1226     return;
1227   }
1228   EnsureSpace ensure_space(this);
1229   EMIT(0xF6);
1230   emit_operand(eax, op);
1231   EMIT(imm8);
1232 }
1233
1234
1235 void Assembler::xor_(Register dst, int32_t imm32) {
1236   EnsureSpace ensure_space(this);
1237   emit_arith(6, Operand(dst), Immediate(imm32));
1238 }
1239
1240
1241 void Assembler::xor_(Register dst, const Operand& src) {
1242   EnsureSpace ensure_space(this);
1243   EMIT(0x33);
1244   emit_operand(dst, src);
1245 }
1246
1247
1248 void Assembler::xor_(const Operand& dst, Register src) {
1249   EnsureSpace ensure_space(this);
1250   EMIT(0x31);
1251   emit_operand(src, dst);
1252 }
1253
1254
1255 void Assembler::xor_(const Operand& dst, const Immediate& x) {
1256   EnsureSpace ensure_space(this);
1257   emit_arith(6, dst, x);
1258 }
1259
1260
1261 void Assembler::bt(const Operand& dst, Register src) {
1262   EnsureSpace ensure_space(this);
1263   EMIT(0x0F);
1264   EMIT(0xA3);
1265   emit_operand(src, dst);
1266 }
1267
1268
1269 void Assembler::bts(const Operand& dst, Register src) {
1270   EnsureSpace ensure_space(this);
1271   EMIT(0x0F);
1272   EMIT(0xAB);
1273   emit_operand(src, dst);
1274 }
1275
1276
1277 void Assembler::bsr(Register dst, const Operand& src) {
1278   EnsureSpace ensure_space(this);
1279   EMIT(0x0F);
1280   EMIT(0xBD);
1281   emit_operand(dst, src);
1282 }
1283
1284
1285 void Assembler::hlt() {
1286   EnsureSpace ensure_space(this);
1287   EMIT(0xF4);
1288 }
1289
1290
1291 void Assembler::int3() {
1292   EnsureSpace ensure_space(this);
1293   EMIT(0xCC);
1294 }
1295
1296
1297 void Assembler::nop() {
1298   EnsureSpace ensure_space(this);
1299   EMIT(0x90);
1300 }
1301
1302
1303 void Assembler::ret(int imm16) {
1304   EnsureSpace ensure_space(this);
1305   DCHECK(is_uint16(imm16));
1306   if (imm16 == 0) {
1307     EMIT(0xC3);
1308   } else {
1309     EMIT(0xC2);
1310     EMIT(imm16 & 0xFF);
1311     EMIT((imm16 >> 8) & 0xFF);
1312   }
1313 }
1314
1315
1316 // Labels refer to positions in the (to be) generated code.
1317 // There are bound, linked, and unused labels.
1318 //
1319 // Bound labels refer to known positions in the already
1320 // generated code. pos() is the position the label refers to.
1321 //
1322 // Linked labels refer to unknown positions in the code
1323 // to be generated; pos() is the position of the 32bit
1324 // Displacement of the last instruction using the label.
1325
1326
1327 void Assembler::print(Label* L) {
1328   if (L->is_unused()) {
1329     PrintF("unused label\n");
1330   } else if (L->is_bound()) {
1331     PrintF("bound label to %d\n", L->pos());
1332   } else if (L->is_linked()) {
1333     Label l = *L;
1334     PrintF("unbound label");
1335     while (l.is_linked()) {
1336       Displacement disp = disp_at(&l);
1337       PrintF("@ %d ", l.pos());
1338       disp.print();
1339       PrintF("\n");
1340       disp.next(&l);
1341     }
1342   } else {
1343     PrintF("label in inconsistent state (pos = %d)\n", L->pos_);
1344   }
1345 }
1346
1347
1348 void Assembler::bind_to(Label* L, int pos) {
1349   EnsureSpace ensure_space(this);
1350   DCHECK(0 <= pos && pos <= pc_offset());  // must have a valid binding position
1351   while (L->is_linked()) {
1352     Displacement disp = disp_at(L);
1353     int fixup_pos = L->pos();
1354     if (disp.type() == Displacement::CODE_RELATIVE) {
1355       // Relative to Code* heap object pointer.
1356       long_at_put(fixup_pos, pos + Code::kHeaderSize - kHeapObjectTag);
1357     } else {
1358       if (disp.type() == Displacement::UNCONDITIONAL_JUMP) {
1359         DCHECK(byte_at(fixup_pos - 1) == 0xE9);  // jmp expected
1360       }
1361       // Relative address, relative to point after address.
1362       int imm32 = pos - (fixup_pos + sizeof(int32_t));
1363       long_at_put(fixup_pos, imm32);
1364     }
1365     disp.next(L);
1366   }
1367   while (L->is_near_linked()) {
1368     int fixup_pos = L->near_link_pos();
1369     int offset_to_next =
1370         static_cast<int>(*reinterpret_cast<int8_t*>(addr_at(fixup_pos)));
1371     DCHECK(offset_to_next <= 0);
1372     // Relative address, relative to point after address.
1373     int disp = pos - fixup_pos - sizeof(int8_t);
1374     CHECK(0 <= disp && disp <= 127);
1375     set_byte_at(fixup_pos, disp);
1376     if (offset_to_next < 0) {
1377       L->link_to(fixup_pos + offset_to_next, Label::kNear);
1378     } else {
1379       L->UnuseNear();
1380     }
1381   }
1382   L->bind_to(pos);
1383 }
1384
1385
1386 void Assembler::bind(Label* L) {
1387   EnsureSpace ensure_space(this);
1388   DCHECK(!L->is_bound());  // label can only be bound once
1389   bind_to(L, pc_offset());
1390 }
1391
1392
1393 void Assembler::call(Label* L) {
1394   positions_recorder()->WriteRecordedPositions();
1395   EnsureSpace ensure_space(this);
1396   if (L->is_bound()) {
1397     const int long_size = 5;
1398     int offs = L->pos() - pc_offset();
1399     DCHECK(offs <= 0);
1400     // 1110 1000 #32-bit disp.
1401     EMIT(0xE8);
1402     emit(offs - long_size);
1403   } else {
1404     // 1110 1000 #32-bit disp.
1405     EMIT(0xE8);
1406     emit_disp(L, Displacement::OTHER);
1407   }
1408 }
1409
1410
1411 void Assembler::call(byte* entry, RelocInfo::Mode rmode) {
1412   positions_recorder()->WriteRecordedPositions();
1413   EnsureSpace ensure_space(this);
1414   DCHECK(!RelocInfo::IsCodeTarget(rmode));
1415   EMIT(0xE8);
1416   if (RelocInfo::IsRuntimeEntry(rmode)) {
1417     emit(reinterpret_cast<uint32_t>(entry), rmode);
1418   } else {
1419     emit(entry - (pc_ + sizeof(int32_t)), rmode);
1420   }
1421 }
1422
1423
1424 int Assembler::CallSize(const Operand& adr) {
1425   // Call size is 1 (opcode) + adr.len_ (operand).
1426   return 1 + adr.len_;
1427 }
1428
1429
1430 void Assembler::call(const Operand& adr) {
1431   positions_recorder()->WriteRecordedPositions();
1432   EnsureSpace ensure_space(this);
1433   EMIT(0xFF);
1434   emit_operand(edx, adr);
1435 }
1436
1437
1438 int Assembler::CallSize(Handle<Code> code, RelocInfo::Mode rmode) {
1439   return 1 /* EMIT */ + sizeof(uint32_t) /* emit */;
1440 }
1441
1442
1443 void Assembler::call(Handle<Code> code,
1444                      RelocInfo::Mode rmode,
1445                      TypeFeedbackId ast_id) {
1446   positions_recorder()->WriteRecordedPositions();
1447   EnsureSpace ensure_space(this);
1448   DCHECK(RelocInfo::IsCodeTarget(rmode)
1449       || rmode == RelocInfo::CODE_AGE_SEQUENCE);
1450   EMIT(0xE8);
1451   emit(code, rmode, ast_id);
1452 }
1453
1454
1455 void Assembler::jmp(Label* L, Label::Distance distance) {
1456   EnsureSpace ensure_space(this);
1457   if (L->is_bound()) {
1458     const int short_size = 2;
1459     const int long_size  = 5;
1460     int offs = L->pos() - pc_offset();
1461     DCHECK(offs <= 0);
1462     if (is_int8(offs - short_size)) {
1463       // 1110 1011 #8-bit disp.
1464       EMIT(0xEB);
1465       EMIT((offs - short_size) & 0xFF);
1466     } else {
1467       // 1110 1001 #32-bit disp.
1468       EMIT(0xE9);
1469       emit(offs - long_size);
1470     }
1471   } else if (distance == Label::kNear) {
1472     EMIT(0xEB);
1473     emit_near_disp(L);
1474   } else {
1475     // 1110 1001 #32-bit disp.
1476     EMIT(0xE9);
1477     emit_disp(L, Displacement::UNCONDITIONAL_JUMP);
1478   }
1479 }
1480
1481
1482 void Assembler::jmp(byte* entry, RelocInfo::Mode rmode) {
1483   EnsureSpace ensure_space(this);
1484   DCHECK(!RelocInfo::IsCodeTarget(rmode));
1485   EMIT(0xE9);
1486   if (RelocInfo::IsRuntimeEntry(rmode)) {
1487     emit(reinterpret_cast<uint32_t>(entry), rmode);
1488   } else {
1489     emit(entry - (pc_ + sizeof(int32_t)), rmode);
1490   }
1491 }
1492
1493
1494 void Assembler::jmp(const Operand& adr) {
1495   EnsureSpace ensure_space(this);
1496   EMIT(0xFF);
1497   emit_operand(esp, adr);
1498 }
1499
1500
1501 void Assembler::jmp(Handle<Code> code, RelocInfo::Mode rmode) {
1502   EnsureSpace ensure_space(this);
1503   DCHECK(RelocInfo::IsCodeTarget(rmode));
1504   EMIT(0xE9);
1505   emit(code, rmode);
1506 }
1507
1508
1509 void Assembler::j(Condition cc, Label* L, Label::Distance distance) {
1510   EnsureSpace ensure_space(this);
1511   DCHECK(0 <= cc && static_cast<int>(cc) < 16);
1512   if (L->is_bound()) {
1513     const int short_size = 2;
1514     const int long_size  = 6;
1515     int offs = L->pos() - pc_offset();
1516     DCHECK(offs <= 0);
1517     if (is_int8(offs - short_size)) {
1518       // 0111 tttn #8-bit disp
1519       EMIT(0x70 | cc);
1520       EMIT((offs - short_size) & 0xFF);
1521     } else {
1522       // 0000 1111 1000 tttn #32-bit disp
1523       EMIT(0x0F);
1524       EMIT(0x80 | cc);
1525       emit(offs - long_size);
1526     }
1527   } else if (distance == Label::kNear) {
1528     EMIT(0x70 | cc);
1529     emit_near_disp(L);
1530   } else {
1531     // 0000 1111 1000 tttn #32-bit disp
1532     // Note: could eliminate cond. jumps to this jump if condition
1533     //       is the same however, seems to be rather unlikely case.
1534     EMIT(0x0F);
1535     EMIT(0x80 | cc);
1536     emit_disp(L, Displacement::OTHER);
1537   }
1538 }
1539
1540
1541 void Assembler::j(Condition cc, byte* entry, RelocInfo::Mode rmode) {
1542   EnsureSpace ensure_space(this);
1543   DCHECK((0 <= cc) && (static_cast<int>(cc) < 16));
1544   // 0000 1111 1000 tttn #32-bit disp.
1545   EMIT(0x0F);
1546   EMIT(0x80 | cc);
1547   if (RelocInfo::IsRuntimeEntry(rmode)) {
1548     emit(reinterpret_cast<uint32_t>(entry), rmode);
1549   } else {
1550     emit(entry - (pc_ + sizeof(int32_t)), rmode);
1551   }
1552 }
1553
1554
1555 void Assembler::j(Condition cc, Handle<Code> code) {
1556   EnsureSpace ensure_space(this);
1557   // 0000 1111 1000 tttn #32-bit disp
1558   EMIT(0x0F);
1559   EMIT(0x80 | cc);
1560   emit(code, RelocInfo::CODE_TARGET);
1561 }
1562
1563
1564 // FPU instructions.
1565
1566 void Assembler::fld(int i) {
1567   EnsureSpace ensure_space(this);
1568   emit_farith(0xD9, 0xC0, i);
1569 }
1570
1571
1572 void Assembler::fstp(int i) {
1573   EnsureSpace ensure_space(this);
1574   emit_farith(0xDD, 0xD8, i);
1575 }
1576
1577
1578 void Assembler::fld1() {
1579   EnsureSpace ensure_space(this);
1580   EMIT(0xD9);
1581   EMIT(0xE8);
1582 }
1583
1584
1585 void Assembler::fldpi() {
1586   EnsureSpace ensure_space(this);
1587   EMIT(0xD9);
1588   EMIT(0xEB);
1589 }
1590
1591
1592 void Assembler::fldz() {
1593   EnsureSpace ensure_space(this);
1594   EMIT(0xD9);
1595   EMIT(0xEE);
1596 }
1597
1598
1599 void Assembler::fldln2() {
1600   EnsureSpace ensure_space(this);
1601   EMIT(0xD9);
1602   EMIT(0xED);
1603 }
1604
1605
1606 void Assembler::fld_s(const Operand& adr) {
1607   EnsureSpace ensure_space(this);
1608   EMIT(0xD9);
1609   emit_operand(eax, adr);
1610 }
1611
1612
1613 void Assembler::fld_d(const Operand& adr) {
1614   EnsureSpace ensure_space(this);
1615   EMIT(0xDD);
1616   emit_operand(eax, adr);
1617 }
1618
1619
1620 void Assembler::fstp_s(const Operand& adr) {
1621   EnsureSpace ensure_space(this);
1622   EMIT(0xD9);
1623   emit_operand(ebx, adr);
1624 }
1625
1626
1627 void Assembler::fst_s(const Operand& adr) {
1628   EnsureSpace ensure_space(this);
1629   EMIT(0xD9);
1630   emit_operand(edx, adr);
1631 }
1632
1633
1634 void Assembler::fstp_d(const Operand& adr) {
1635   EnsureSpace ensure_space(this);
1636   EMIT(0xDD);
1637   emit_operand(ebx, adr);
1638 }
1639
1640
1641 void Assembler::fst_d(const Operand& adr) {
1642   EnsureSpace ensure_space(this);
1643   EMIT(0xDD);
1644   emit_operand(edx, adr);
1645 }
1646
1647
1648 void Assembler::fild_s(const Operand& adr) {
1649   EnsureSpace ensure_space(this);
1650   EMIT(0xDB);
1651   emit_operand(eax, adr);
1652 }
1653
1654
1655 void Assembler::fild_d(const Operand& adr) {
1656   EnsureSpace ensure_space(this);
1657   EMIT(0xDF);
1658   emit_operand(ebp, adr);
1659 }
1660
1661
1662 void Assembler::fistp_s(const Operand& adr) {
1663   EnsureSpace ensure_space(this);
1664   EMIT(0xDB);
1665   emit_operand(ebx, adr);
1666 }
1667
1668
1669 void Assembler::fisttp_s(const Operand& adr) {
1670   DCHECK(IsEnabled(SSE3));
1671   EnsureSpace ensure_space(this);
1672   EMIT(0xDB);
1673   emit_operand(ecx, adr);
1674 }
1675
1676
1677 void Assembler::fisttp_d(const Operand& adr) {
1678   DCHECK(IsEnabled(SSE3));
1679   EnsureSpace ensure_space(this);
1680   EMIT(0xDD);
1681   emit_operand(ecx, adr);
1682 }
1683
1684
1685 void Assembler::fist_s(const Operand& adr) {
1686   EnsureSpace ensure_space(this);
1687   EMIT(0xDB);
1688   emit_operand(edx, adr);
1689 }
1690
1691
1692 void Assembler::fistp_d(const Operand& adr) {
1693   EnsureSpace ensure_space(this);
1694   EMIT(0xDF);
1695   emit_operand(edi, adr);
1696 }
1697
1698
1699 void Assembler::fabs() {
1700   EnsureSpace ensure_space(this);
1701   EMIT(0xD9);
1702   EMIT(0xE1);
1703 }
1704
1705
1706 void Assembler::fchs() {
1707   EnsureSpace ensure_space(this);
1708   EMIT(0xD9);
1709   EMIT(0xE0);
1710 }
1711
1712
1713 void Assembler::fcos() {
1714   EnsureSpace ensure_space(this);
1715   EMIT(0xD9);
1716   EMIT(0xFF);
1717 }
1718
1719
1720 void Assembler::fsin() {
1721   EnsureSpace ensure_space(this);
1722   EMIT(0xD9);
1723   EMIT(0xFE);
1724 }
1725
1726
1727 void Assembler::fptan() {
1728   EnsureSpace ensure_space(this);
1729   EMIT(0xD9);
1730   EMIT(0xF2);
1731 }
1732
1733
1734 void Assembler::fyl2x() {
1735   EnsureSpace ensure_space(this);
1736   EMIT(0xD9);
1737   EMIT(0xF1);
1738 }
1739
1740
1741 void Assembler::f2xm1() {
1742   EnsureSpace ensure_space(this);
1743   EMIT(0xD9);
1744   EMIT(0xF0);
1745 }
1746
1747
1748 void Assembler::fscale() {
1749   EnsureSpace ensure_space(this);
1750   EMIT(0xD9);
1751   EMIT(0xFD);
1752 }
1753
1754
1755 void Assembler::fninit() {
1756   EnsureSpace ensure_space(this);
1757   EMIT(0xDB);
1758   EMIT(0xE3);
1759 }
1760
1761
1762 void Assembler::fadd(int i) {
1763   EnsureSpace ensure_space(this);
1764   emit_farith(0xDC, 0xC0, i);
1765 }
1766
1767
1768 void Assembler::fadd_i(int i) {
1769   EnsureSpace ensure_space(this);
1770   emit_farith(0xD8, 0xC0, i);
1771 }
1772
1773
1774 void Assembler::fsub(int i) {
1775   EnsureSpace ensure_space(this);
1776   emit_farith(0xDC, 0xE8, i);
1777 }
1778
1779
1780 void Assembler::fsub_i(int i) {
1781   EnsureSpace ensure_space(this);
1782   emit_farith(0xD8, 0xE0, i);
1783 }
1784
1785
1786 void Assembler::fisub_s(const Operand& adr) {
1787   EnsureSpace ensure_space(this);
1788   EMIT(0xDA);
1789   emit_operand(esp, adr);
1790 }
1791
1792
1793 void Assembler::fmul_i(int i) {
1794   EnsureSpace ensure_space(this);
1795   emit_farith(0xD8, 0xC8, i);
1796 }
1797
1798
1799 void Assembler::fmul(int i) {
1800   EnsureSpace ensure_space(this);
1801   emit_farith(0xDC, 0xC8, i);
1802 }
1803
1804
1805 void Assembler::fdiv(int i) {
1806   EnsureSpace ensure_space(this);
1807   emit_farith(0xDC, 0xF8, i);
1808 }
1809
1810
1811 void Assembler::fdiv_i(int i) {
1812   EnsureSpace ensure_space(this);
1813   emit_farith(0xD8, 0xF0, i);
1814 }
1815
1816
1817 void Assembler::faddp(int i) {
1818   EnsureSpace ensure_space(this);
1819   emit_farith(0xDE, 0xC0, i);
1820 }
1821
1822
1823 void Assembler::fsubp(int i) {
1824   EnsureSpace ensure_space(this);
1825   emit_farith(0xDE, 0xE8, i);
1826 }
1827
1828
1829 void Assembler::fsubrp(int i) {
1830   EnsureSpace ensure_space(this);
1831   emit_farith(0xDE, 0xE0, i);
1832 }
1833
1834
1835 void Assembler::fmulp(int i) {
1836   EnsureSpace ensure_space(this);
1837   emit_farith(0xDE, 0xC8, i);
1838 }
1839
1840
1841 void Assembler::fdivp(int i) {
1842   EnsureSpace ensure_space(this);
1843   emit_farith(0xDE, 0xF8, i);
1844 }
1845
1846
1847 void Assembler::fprem() {
1848   EnsureSpace ensure_space(this);
1849   EMIT(0xD9);
1850   EMIT(0xF8);
1851 }
1852
1853
1854 void Assembler::fprem1() {
1855   EnsureSpace ensure_space(this);
1856   EMIT(0xD9);
1857   EMIT(0xF5);
1858 }
1859
1860
1861 void Assembler::fxch(int i) {
1862   EnsureSpace ensure_space(this);
1863   emit_farith(0xD9, 0xC8, i);
1864 }
1865
1866
1867 void Assembler::fincstp() {
1868   EnsureSpace ensure_space(this);
1869   EMIT(0xD9);
1870   EMIT(0xF7);
1871 }
1872
1873
1874 void Assembler::ffree(int i) {
1875   EnsureSpace ensure_space(this);
1876   emit_farith(0xDD, 0xC0, i);
1877 }
1878
1879
1880 void Assembler::ftst() {
1881   EnsureSpace ensure_space(this);
1882   EMIT(0xD9);
1883   EMIT(0xE4);
1884 }
1885
1886
1887 void Assembler::fucomp(int i) {
1888   EnsureSpace ensure_space(this);
1889   emit_farith(0xDD, 0xE8, i);
1890 }
1891
1892
1893 void Assembler::fucompp() {
1894   EnsureSpace ensure_space(this);
1895   EMIT(0xDA);
1896   EMIT(0xE9);
1897 }
1898
1899
1900 void Assembler::fucomi(int i) {
1901   EnsureSpace ensure_space(this);
1902   EMIT(0xDB);
1903   EMIT(0xE8 + i);
1904 }
1905
1906
1907 void Assembler::fucomip() {
1908   EnsureSpace ensure_space(this);
1909   EMIT(0xDF);
1910   EMIT(0xE9);
1911 }
1912
1913
1914 void Assembler::fcompp() {
1915   EnsureSpace ensure_space(this);
1916   EMIT(0xDE);
1917   EMIT(0xD9);
1918 }
1919
1920
1921 void Assembler::fnstsw_ax() {
1922   EnsureSpace ensure_space(this);
1923   EMIT(0xDF);
1924   EMIT(0xE0);
1925 }
1926
1927
1928 void Assembler::fwait() {
1929   EnsureSpace ensure_space(this);
1930   EMIT(0x9B);
1931 }
1932
1933
1934 void Assembler::frndint() {
1935   EnsureSpace ensure_space(this);
1936   EMIT(0xD9);
1937   EMIT(0xFC);
1938 }
1939
1940
1941 void Assembler::fnclex() {
1942   EnsureSpace ensure_space(this);
1943   EMIT(0xDB);
1944   EMIT(0xE2);
1945 }
1946
1947
1948 void Assembler::sahf() {
1949   EnsureSpace ensure_space(this);
1950   EMIT(0x9E);
1951 }
1952
1953
1954 void Assembler::setcc(Condition cc, Register reg) {
1955   DCHECK(reg.is_byte_register());
1956   EnsureSpace ensure_space(this);
1957   EMIT(0x0F);
1958   EMIT(0x90 | cc);
1959   EMIT(0xC0 | reg.code());
1960 }
1961
1962
1963 void Assembler::cvttss2si(Register dst, const Operand& src) {
1964   EnsureSpace ensure_space(this);
1965   EMIT(0xF3);
1966   EMIT(0x0F);
1967   EMIT(0x2C);
1968   emit_operand(dst, src);
1969 }
1970
1971
1972 void Assembler::cvttsd2si(Register dst, const Operand& src) {
1973   EnsureSpace ensure_space(this);
1974   EMIT(0xF2);
1975   EMIT(0x0F);
1976   EMIT(0x2C);
1977   emit_operand(dst, src);
1978 }
1979
1980
1981 void Assembler::cvtsd2si(Register dst, XMMRegister src) {
1982   EnsureSpace ensure_space(this);
1983   EMIT(0xF2);
1984   EMIT(0x0F);
1985   EMIT(0x2D);
1986   emit_sse_operand(dst, src);
1987 }
1988
1989
1990 void Assembler::cvtsi2sd(XMMRegister dst, const Operand& src) {
1991   EnsureSpace ensure_space(this);
1992   EMIT(0xF2);
1993   EMIT(0x0F);
1994   EMIT(0x2A);
1995   emit_sse_operand(dst, src);
1996 }
1997
1998
1999 void Assembler::cvtss2sd(XMMRegister dst, XMMRegister src) {
2000   EnsureSpace ensure_space(this);
2001   EMIT(0xF3);
2002   EMIT(0x0F);
2003   EMIT(0x5A);
2004   emit_sse_operand(dst, src);
2005 }
2006
2007
2008 void Assembler::cvtsd2ss(XMMRegister dst, XMMRegister src) {
2009   EnsureSpace ensure_space(this);
2010   EMIT(0xF2);
2011   EMIT(0x0F);
2012   EMIT(0x5A);
2013   emit_sse_operand(dst, src);
2014 }
2015
2016
2017 void Assembler::addsd(XMMRegister dst, XMMRegister src) {
2018   EnsureSpace ensure_space(this);
2019   EMIT(0xF2);
2020   EMIT(0x0F);
2021   EMIT(0x58);
2022   emit_sse_operand(dst, src);
2023 }
2024
2025
2026 void Assembler::addsd(XMMRegister dst, const Operand& src) {
2027   EnsureSpace ensure_space(this);
2028   EMIT(0xF2);
2029   EMIT(0x0F);
2030   EMIT(0x58);
2031   emit_sse_operand(dst, src);
2032 }
2033
2034
2035 void Assembler::mulsd(XMMRegister dst, XMMRegister src) {
2036   EnsureSpace ensure_space(this);
2037   EMIT(0xF2);
2038   EMIT(0x0F);
2039   EMIT(0x59);
2040   emit_sse_operand(dst, src);
2041 }
2042
2043
2044 void Assembler::mulsd(XMMRegister dst, const Operand& src) {
2045   EnsureSpace ensure_space(this);
2046   EMIT(0xF2);
2047   EMIT(0x0F);
2048   EMIT(0x59);
2049   emit_sse_operand(dst, src);
2050 }
2051
2052
2053 void Assembler::subsd(XMMRegister dst, XMMRegister src) {
2054   EnsureSpace ensure_space(this);
2055   EMIT(0xF2);
2056   EMIT(0x0F);
2057   EMIT(0x5C);
2058   emit_sse_operand(dst, src);
2059 }
2060
2061
2062 void Assembler::divsd(XMMRegister dst, XMMRegister src) {
2063   EnsureSpace ensure_space(this);
2064   EMIT(0xF2);
2065   EMIT(0x0F);
2066   EMIT(0x5E);
2067   emit_sse_operand(dst, src);
2068 }
2069
2070
2071 void Assembler::xorpd(XMMRegister dst, XMMRegister src) {
2072   EnsureSpace ensure_space(this);
2073   EMIT(0x66);
2074   EMIT(0x0F);
2075   EMIT(0x57);
2076   emit_sse_operand(dst, src);
2077 }
2078
2079
2080 void Assembler::xorpd(XMMRegister dst, const Operand& src) {
2081   EnsureSpace ensure_space(this);
2082   EMIT(0x66);
2083   EMIT(0x0F);
2084   EMIT(0x57);
2085   emit_sse_operand(dst, src);
2086 }
2087
2088
2089 void Assembler::andps(XMMRegister dst, const Operand& src) {
2090   EnsureSpace ensure_space(this);
2091   EMIT(0x0F);
2092   EMIT(0x54);
2093   emit_sse_operand(dst, src);
2094 }
2095
2096
2097 void Assembler::orps(XMMRegister dst, const Operand& src) {
2098   EnsureSpace ensure_space(this);
2099   EMIT(0x0F);
2100   EMIT(0x56);
2101   emit_sse_operand(dst, src);
2102 }
2103
2104
2105 void Assembler::xorps(XMMRegister dst, const Operand& src) {
2106   EnsureSpace ensure_space(this);
2107   EMIT(0x0F);
2108   EMIT(0x57);
2109   emit_sse_operand(dst, src);
2110 }
2111
2112
2113 void Assembler::addps(XMMRegister dst, const Operand& src) {
2114   EnsureSpace ensure_space(this);
2115   EMIT(0x0F);
2116   EMIT(0x58);
2117   emit_sse_operand(dst, src);
2118 }
2119
2120
2121 void Assembler::subps(XMMRegister dst, const Operand& src) {
2122   EnsureSpace ensure_space(this);
2123   EMIT(0x0F);
2124   EMIT(0x5C);
2125   emit_sse_operand(dst, src);
2126 }
2127
2128
2129 void Assembler::mulps(XMMRegister dst, const Operand& src) {
2130   EnsureSpace ensure_space(this);
2131   EMIT(0x0F);
2132   EMIT(0x59);
2133   emit_sse_operand(dst, src);
2134 }
2135
2136
2137 void Assembler::divps(XMMRegister dst, const Operand& src) {
2138   EnsureSpace ensure_space(this);
2139   EMIT(0x0F);
2140   EMIT(0x5E);
2141   emit_sse_operand(dst, src);
2142 }
2143
2144
2145 void Assembler::addpd(XMMRegister dst, const Operand& src) {
2146   EnsureSpace ensure_space(this);
2147   EMIT(0x66);
2148   EMIT(0x0F);
2149   EMIT(0x58);
2150   emit_sse_operand(dst, src);
2151 }
2152
2153
2154 void Assembler::subpd(XMMRegister dst, const Operand& src) {
2155   EnsureSpace ensure_space(this);
2156   EMIT(0x66);
2157   EMIT(0x0F);
2158   EMIT(0x5C);
2159   emit_sse_operand(dst, src);
2160 }
2161
2162
2163 void Assembler::mulpd(XMMRegister dst, const Operand& src) {
2164   EnsureSpace ensure_space(this);
2165   EMIT(0x66);
2166   EMIT(0x0F);
2167   EMIT(0x59);
2168   emit_sse_operand(dst, src);
2169 }
2170
2171
2172 void Assembler::divpd(XMMRegister dst, const Operand& src) {
2173   EnsureSpace ensure_space(this);
2174   EMIT(0x66);
2175   EMIT(0x0F);
2176   EMIT(0x5E);
2177   emit_sse_operand(dst, src);
2178 }
2179
2180
2181 void Assembler::sqrtsd(XMMRegister dst, XMMRegister src) {
2182   EnsureSpace ensure_space(this);
2183   EMIT(0xF2);
2184   EMIT(0x0F);
2185   EMIT(0x51);
2186   emit_sse_operand(dst, src);
2187 }
2188
2189
2190 void Assembler::sqrtsd(XMMRegister dst, const Operand& src) {
2191   EnsureSpace ensure_space(this);
2192   EMIT(0xF2);
2193   EMIT(0x0F);
2194   EMIT(0x51);
2195   emit_sse_operand(dst, src);
2196 }
2197
2198
2199 void Assembler::andpd(XMMRegister dst, XMMRegister src) {
2200   EnsureSpace ensure_space(this);
2201   EMIT(0x66);
2202   EMIT(0x0F);
2203   EMIT(0x54);
2204   emit_sse_operand(dst, src);
2205 }
2206
2207
2208 void Assembler::andpd(XMMRegister dst, const Operand& src) {
2209   EnsureSpace ensure_space(this);
2210   EMIT(0x66);
2211   EMIT(0x0F);
2212   EMIT(0x54);
2213   emit_sse_operand(dst, src);
2214 }
2215
2216
2217 void Assembler::orpd(XMMRegister dst, XMMRegister src) {
2218   EnsureSpace ensure_space(this);
2219   EMIT(0x66);
2220   EMIT(0x0F);
2221   EMIT(0x56);
2222   emit_sse_operand(dst, src);
2223 }
2224
2225
2226 void Assembler::ucomisd(XMMRegister dst, const Operand& src) {
2227   EnsureSpace ensure_space(this);
2228   EMIT(0x66);
2229   EMIT(0x0F);
2230   EMIT(0x2E);
2231   emit_sse_operand(dst, src);
2232 }
2233
2234
2235 void Assembler::roundsd(XMMRegister dst, XMMRegister src, RoundingMode mode) {
2236   DCHECK(IsEnabled(SSE4_1));
2237   EnsureSpace ensure_space(this);
2238   EMIT(0x66);
2239   EMIT(0x0F);
2240   EMIT(0x3A);
2241   EMIT(0x0B);
2242   emit_sse_operand(dst, src);
2243   // Mask precision exeption.
2244   EMIT(static_cast<byte>(mode) | 0x8);
2245 }
2246
2247
2248 void Assembler::movmskpd(Register dst, XMMRegister src) {
2249   EnsureSpace ensure_space(this);
2250   EMIT(0x66);
2251   EMIT(0x0F);
2252   EMIT(0x50);
2253   emit_sse_operand(dst, src);
2254 }
2255
2256
2257 void Assembler::movmskps(Register dst, XMMRegister src) {
2258   EnsureSpace ensure_space(this);
2259   EMIT(0x0F);
2260   EMIT(0x50);
2261   emit_sse_operand(dst, src);
2262 }
2263
2264
2265 void Assembler::pcmpeqd(XMMRegister dst, XMMRegister src) {
2266   EnsureSpace ensure_space(this);
2267   EMIT(0x66);
2268   EMIT(0x0F);
2269   EMIT(0x76);
2270   emit_sse_operand(dst, src);
2271 }
2272
2273
2274 void Assembler::pcmpgtd(XMMRegister dst, XMMRegister src) {
2275   EnsureSpace ensure_space(this);
2276   EMIT(0x66);
2277   EMIT(0x0F);
2278   EMIT(0x66);
2279   emit_sse_operand(dst, src);
2280 }
2281
2282
2283 void Assembler::cmpltsd(XMMRegister dst, XMMRegister src) {
2284   EnsureSpace ensure_space(this);
2285   EMIT(0xF2);
2286   EMIT(0x0F);
2287   EMIT(0xC2);
2288   emit_sse_operand(dst, src);
2289   EMIT(1);  // LT == 1
2290 }
2291
2292
2293 void Assembler::movaps(XMMRegister dst, XMMRegister src) {
2294   EnsureSpace ensure_space(this);
2295   EMIT(0x0F);
2296   EMIT(0x28);
2297   emit_sse_operand(dst, src);
2298 }
2299
2300
2301 void Assembler::movups(XMMRegister dst, const Operand& src) {
2302   EnsureSpace ensure_space(this);
2303   EMIT(0x0F);
2304   EMIT(0x10);
2305   emit_sse_operand(dst, src);
2306 }
2307
2308
2309 void Assembler::movups(const Operand& dst, XMMRegister src) {
2310   EnsureSpace ensure_space(this);
2311   EMIT(0x0F);
2312   EMIT(0x11);
2313   emit_sse_operand(src, dst);
2314 }
2315
2316
2317 void Assembler::shufps(XMMRegister dst, XMMRegister src, byte imm8) {
2318   DCHECK(is_uint8(imm8));
2319   EnsureSpace ensure_space(this);
2320   EMIT(0x0F);
2321   EMIT(0xC6);
2322   emit_sse_operand(dst, src);
2323   EMIT(imm8);
2324 }
2325
2326
2327 void Assembler::shufpd(XMMRegister dst, XMMRegister src, byte imm8) {
2328     DCHECK(is_uint8(imm8));
2329   EnsureSpace ensure_space(this);
2330   EMIT(0x66);
2331   EMIT(0x0F);
2332   EMIT(0xC6);
2333   emit_sse_operand(dst, src);
2334   EMIT(imm8);
2335 }
2336
2337
2338 void Assembler::movdqa(const Operand& dst, XMMRegister src) {
2339   EnsureSpace ensure_space(this);
2340   EMIT(0x66);
2341   EMIT(0x0F);
2342   EMIT(0x7F);
2343   emit_sse_operand(src, dst);
2344 }
2345
2346
2347 void Assembler::movdqa(XMMRegister dst, const Operand& src) {
2348   EnsureSpace ensure_space(this);
2349   EMIT(0x66);
2350   EMIT(0x0F);
2351   EMIT(0x6F);
2352   emit_sse_operand(dst, src);
2353 }
2354
2355
2356 void Assembler::movdqu(const Operand& dst, XMMRegister src ) {
2357   EnsureSpace ensure_space(this);
2358   EMIT(0xF3);
2359   EMIT(0x0F);
2360   EMIT(0x7F);
2361   emit_sse_operand(src, dst);
2362 }
2363
2364
2365 void Assembler::movdqu(XMMRegister dst, const Operand& src) {
2366   EnsureSpace ensure_space(this);
2367   EMIT(0xF3);
2368   EMIT(0x0F);
2369   EMIT(0x6F);
2370   emit_sse_operand(dst, src);
2371 }
2372
2373
2374 void Assembler::movntdqa(XMMRegister dst, const Operand& src) {
2375   DCHECK(IsEnabled(SSE4_1));
2376   EnsureSpace ensure_space(this);
2377   EMIT(0x66);
2378   EMIT(0x0F);
2379   EMIT(0x38);
2380   EMIT(0x2A);
2381   emit_sse_operand(dst, src);
2382 }
2383
2384
2385 void Assembler::movntdq(const Operand& dst, XMMRegister src) {
2386   EnsureSpace ensure_space(this);
2387   EMIT(0x66);
2388   EMIT(0x0F);
2389   EMIT(0xE7);
2390   emit_sse_operand(src, dst);
2391 }
2392
2393
2394 void Assembler::prefetch(const Operand& src, int level) {
2395   DCHECK(is_uint2(level));
2396   EnsureSpace ensure_space(this);
2397   EMIT(0x0F);
2398   EMIT(0x18);
2399   // Emit hint number in Reg position of RegR/M.
2400   XMMRegister code = XMMRegister::from_code(level);
2401   emit_sse_operand(code, src);
2402 }
2403
2404
2405 void Assembler::movsd(const Operand& dst, XMMRegister src ) {
2406   EnsureSpace ensure_space(this);
2407   EMIT(0xF2);  // double
2408   EMIT(0x0F);
2409   EMIT(0x11);  // store
2410   emit_sse_operand(src, dst);
2411 }
2412
2413
2414 void Assembler::movsd(XMMRegister dst, const Operand& src) {
2415   EnsureSpace ensure_space(this);
2416   EMIT(0xF2);  // double
2417   EMIT(0x0F);
2418   EMIT(0x10);  // load
2419   emit_sse_operand(dst, src);
2420 }
2421
2422
2423 void Assembler::movss(const Operand& dst, XMMRegister src ) {
2424   EnsureSpace ensure_space(this);
2425   EMIT(0xF3);  // float
2426   EMIT(0x0F);
2427   EMIT(0x11);  // store
2428   emit_sse_operand(src, dst);
2429 }
2430
2431
2432 void Assembler::movss(XMMRegister dst, const Operand& src) {
2433   EnsureSpace ensure_space(this);
2434   EMIT(0xF3);  // float
2435   EMIT(0x0F);
2436   EMIT(0x10);  // load
2437   emit_sse_operand(dst, src);
2438 }
2439
2440
2441 void Assembler::movd(XMMRegister dst, const Operand& src) {
2442   EnsureSpace ensure_space(this);
2443   EMIT(0x66);
2444   EMIT(0x0F);
2445   EMIT(0x6E);
2446   emit_sse_operand(dst, src);
2447 }
2448
2449
2450 void Assembler::movd(const Operand& dst, XMMRegister src) {
2451   EnsureSpace ensure_space(this);
2452   EMIT(0x66);
2453   EMIT(0x0F);
2454   EMIT(0x7E);
2455   emit_sse_operand(src, dst);
2456 }
2457
2458
2459 void Assembler::extractps(Register dst, XMMRegister src, byte imm8) {
2460   DCHECK(IsEnabled(SSE4_1));
2461   DCHECK(is_uint8(imm8));
2462   EnsureSpace ensure_space(this);
2463   EMIT(0x66);
2464   EMIT(0x0F);
2465   EMIT(0x3A);
2466   EMIT(0x17);
2467   emit_sse_operand(src, dst);
2468   EMIT(imm8);
2469 }
2470
2471
2472 void Assembler::pand(XMMRegister dst, XMMRegister src) {
2473   EnsureSpace ensure_space(this);
2474   EMIT(0x66);
2475   EMIT(0x0F);
2476   EMIT(0xDB);
2477   emit_sse_operand(dst, src);
2478 }
2479
2480
2481 void Assembler::pxor(XMMRegister dst, XMMRegister src) {
2482   EnsureSpace ensure_space(this);
2483   EMIT(0x66);
2484   EMIT(0x0F);
2485   EMIT(0xEF);
2486   emit_sse_operand(dst, src);
2487 }
2488
2489
2490 void Assembler::por(XMMRegister dst, XMMRegister src) {
2491   EnsureSpace ensure_space(this);
2492   EMIT(0x66);
2493   EMIT(0x0F);
2494   EMIT(0xEB);
2495   emit_sse_operand(dst, src);
2496 }
2497
2498
2499 void Assembler::ptest(XMMRegister dst, XMMRegister src) {
2500   DCHECK(IsEnabled(SSE4_1));
2501   EnsureSpace ensure_space(this);
2502   EMIT(0x66);
2503   EMIT(0x0F);
2504   EMIT(0x38);
2505   EMIT(0x17);
2506   emit_sse_operand(dst, src);
2507 }
2508
2509
2510 void Assembler::psllq(XMMRegister reg, int8_t shift) {
2511   EnsureSpace ensure_space(this);
2512   EMIT(0x66);
2513   EMIT(0x0F);
2514   EMIT(0x73);
2515   emit_sse_operand(esi, reg);  // esi == 6
2516   EMIT(shift);
2517 }
2518
2519
2520 void Assembler::psllq(XMMRegister dst, XMMRegister src) {
2521   EnsureSpace ensure_space(this);
2522   EMIT(0x66);
2523   EMIT(0x0F);
2524   EMIT(0xF3);
2525   emit_sse_operand(dst, src);
2526 }
2527
2528
2529 void Assembler::pslld(XMMRegister reg, int8_t shift) {
2530   EnsureSpace ensure_space(this);
2531   EMIT(0x66);
2532   EMIT(0x0F);
2533   EMIT(0x72);
2534   emit_sse_operand(esi, reg);  // esi == 6
2535   EMIT(shift);
2536 }
2537
2538
2539 void Assembler::pslld(XMMRegister dst, XMMRegister src) {
2540   EnsureSpace ensure_space(this);
2541   EMIT(0x66);
2542   EMIT(0x0F);
2543   EMIT(0xF2);
2544   emit_sse_operand(dst, src);
2545 }
2546
2547
2548 void Assembler::psrld(XMMRegister reg, int8_t shift) {
2549   EnsureSpace ensure_space(this);
2550   EMIT(0x66);
2551   EMIT(0x0F);
2552   EMIT(0x72);
2553   emit_sse_operand(edx, reg);  // edx == 2
2554   EMIT(shift);
2555 }
2556
2557
2558 void Assembler::psrld(XMMRegister dst, XMMRegister src) {
2559   EnsureSpace ensure_space(this);
2560   EMIT(0x66);
2561   EMIT(0x0F);
2562   EMIT(0xD2);
2563   emit_sse_operand(dst, src);
2564 }
2565
2566
2567 void Assembler::psrad(XMMRegister reg, int8_t shift) {
2568   EnsureSpace ensure_space(this);
2569   EMIT(0x66);
2570   EMIT(0x0F);
2571   EMIT(0x72);
2572   emit_sse_operand(esp, reg);  // esp == 4
2573   EMIT(shift);
2574 }
2575
2576
2577 void Assembler::psrad(XMMRegister dst, XMMRegister src) {
2578   EnsureSpace ensure_space(this);
2579   EMIT(0x66);
2580   EMIT(0x0F);
2581   EMIT(0xE2);
2582   emit_sse_operand(dst, src);
2583 }
2584
2585
2586 void Assembler::psrlq(XMMRegister reg, int8_t shift) {
2587   EnsureSpace ensure_space(this);
2588   EMIT(0x66);
2589   EMIT(0x0F);
2590   EMIT(0x73);
2591   emit_sse_operand(edx, reg);  // edx == 2
2592   EMIT(shift);
2593 }
2594
2595
2596 void Assembler::psrlq(XMMRegister dst, XMMRegister src) {
2597   EnsureSpace ensure_space(this);
2598   EMIT(0x66);
2599   EMIT(0x0F);
2600   EMIT(0xD3);
2601   emit_sse_operand(dst, src);
2602 }
2603
2604
2605 void Assembler::psrldq(XMMRegister dst, int8_t shift) {
2606   EnsureSpace ensure_space(this);
2607   EMIT(0x66);
2608   EMIT(0x0F);
2609   EMIT(0x73);
2610   emit_sse_operand(ebx, dst);   // ebx == 3
2611   EMIT(shift);
2612 }
2613
2614
2615 void Assembler::pshufd(XMMRegister dst, XMMRegister src, uint8_t shuffle) {
2616   EnsureSpace ensure_space(this);
2617   EMIT(0x66);
2618   EMIT(0x0F);
2619   EMIT(0x70);
2620   emit_sse_operand(dst, src);
2621   EMIT(shuffle);
2622 }
2623
2624
2625 void Assembler::pextrd(const Operand& dst, XMMRegister src, int8_t offset) {
2626   DCHECK(IsEnabled(SSE4_1));
2627   EnsureSpace ensure_space(this);
2628   EMIT(0x66);
2629   EMIT(0x0F);
2630   EMIT(0x3A);
2631   EMIT(0x16);
2632   emit_sse_operand(src, dst);
2633   EMIT(offset);
2634 }
2635
2636
2637 void Assembler::pinsrd(XMMRegister dst, const Operand& src, int8_t offset) {
2638   DCHECK(IsEnabled(SSE4_1));
2639   EnsureSpace ensure_space(this);
2640   EMIT(0x66);
2641   EMIT(0x0F);
2642   EMIT(0x3A);
2643   EMIT(0x22);
2644   emit_sse_operand(dst, src);
2645   EMIT(offset);
2646 }
2647
2648
2649 void Assembler::minps(XMMRegister dst, const Operand& src) {
2650   EnsureSpace ensure_space(this);
2651   EMIT(0x0F);
2652   EMIT(0x5D);
2653   emit_sse_operand(dst, src);
2654 }
2655
2656
2657 void Assembler::maxps(XMMRegister dst, const Operand& src) {
2658   EnsureSpace ensure_space(this);
2659   EMIT(0x0F);
2660   EMIT(0x5F);
2661   emit_sse_operand(dst, src);
2662 }
2663
2664
2665 void Assembler::minpd(XMMRegister dst, const Operand& src) {
2666   EnsureSpace ensure_space(this);
2667   EMIT(0x66);
2668   EMIT(0x0F);
2669   EMIT(0x5D);
2670   emit_sse_operand(dst, src);
2671 }
2672
2673
2674 void Assembler::maxpd(XMMRegister dst, const Operand& src) {
2675   EnsureSpace ensure_space(this);
2676   EMIT(0x66);
2677   EMIT(0x0F);
2678   EMIT(0x5F);
2679   emit_sse_operand(dst, src);
2680 }
2681
2682
2683 void Assembler::rcpps(XMMRegister dst, const Operand& src) {
2684   EnsureSpace ensure_space(this);
2685   EMIT(0x0F);
2686   EMIT(0x53);
2687   emit_sse_operand(dst, src);
2688 }
2689
2690
2691 void Assembler::rsqrtps(XMMRegister dst, const Operand& src) {
2692   EnsureSpace ensure_space(this);
2693   EMIT(0x0F);
2694   EMIT(0x52);
2695   emit_sse_operand(dst, src);
2696 }
2697
2698
2699 void Assembler::sqrtps(XMMRegister dst, const Operand& src) {
2700   EnsureSpace ensure_space(this);
2701   EMIT(0x0F);
2702   EMIT(0x51);
2703   emit_sse_operand(dst, src);
2704 }
2705
2706
2707 void Assembler::sqrtpd(XMMRegister dst, const Operand& src) {
2708   EnsureSpace ensure_space(this);
2709   EMIT(0x66);
2710   EMIT(0x0F);
2711   EMIT(0x51);
2712   emit_sse_operand(dst, src);
2713 }
2714
2715
2716 void Assembler::cvtdq2ps(XMMRegister dst, const Operand& src) {
2717   EnsureSpace ensure_space(this);
2718   EMIT(0x0F);
2719   EMIT(0x5B);
2720   emit_sse_operand(dst, src);
2721 }
2722
2723
2724 void Assembler::paddd(XMMRegister dst, const Operand& src) {
2725   EnsureSpace ensure_space(this);
2726   EMIT(0x66);
2727   EMIT(0x0F);
2728   EMIT(0xFE);
2729   emit_sse_operand(dst, src);
2730 }
2731
2732
2733 void Assembler::psubd(XMMRegister dst, const Operand& src) {
2734   EnsureSpace ensure_space(this);
2735   EMIT(0x66);
2736   EMIT(0x0F);
2737   EMIT(0xFA);
2738   emit_sse_operand(dst, src);
2739 }
2740
2741
2742 void Assembler::pmulld(XMMRegister dst, const Operand& src) {
2743   DCHECK(IsEnabled(SSE4_1));
2744   EnsureSpace ensure_space(this);
2745   EMIT(0x66);
2746   EMIT(0x0F);
2747   EMIT(0x38);
2748   EMIT(0x40);
2749   emit_sse_operand(dst, src);
2750 }
2751
2752
2753 void Assembler::pmuludq(XMMRegister dst, const Operand& src) {
2754   EnsureSpace ensure_space(this);
2755   EMIT(0x66);
2756   EMIT(0x0F);
2757   EMIT(0xF4);
2758   emit_sse_operand(dst, src);
2759 }
2760
2761
2762 void Assembler::punpackldq(XMMRegister dst, const Operand& src) {
2763   EnsureSpace ensure_space(this);
2764   EMIT(0x66);
2765   EMIT(0x0F);
2766   EMIT(0x62);
2767   emit_sse_operand(dst, src);
2768 }
2769
2770
2771 void Assembler::cvtps2dq(XMMRegister dst, const Operand& src) {
2772   EnsureSpace ensure_space(this);
2773   EMIT(0x66);
2774   EMIT(0x0F);
2775   EMIT(0x5B);
2776   emit_sse_operand(dst, src);
2777 }
2778
2779
2780 void Assembler::cmpps(XMMRegister dst, XMMRegister src, int8_t cmp) {
2781   EnsureSpace ensure_space(this);
2782   EMIT(0x0F);
2783   EMIT(0xC2);
2784   emit_sse_operand(dst, src);
2785   EMIT(cmp);
2786 }
2787
2788
2789 void Assembler::cmpeqps(XMMRegister dst, XMMRegister src) {
2790   cmpps(dst, src, 0x0);
2791 }
2792
2793
2794 void Assembler::cmpltps(XMMRegister dst, XMMRegister src) {
2795   cmpps(dst, src, 0x1);
2796 }
2797
2798
2799 void Assembler::cmpleps(XMMRegister dst, XMMRegister src) {
2800   cmpps(dst, src, 0x2);
2801 }
2802
2803
2804 void Assembler::cmpneqps(XMMRegister dst, XMMRegister src) {
2805   cmpps(dst, src, 0x4);
2806 }
2807
2808
2809 void Assembler::cmpnltps(XMMRegister dst, XMMRegister src) {
2810   cmpps(dst, src, 0x5);
2811 }
2812
2813
2814 void Assembler::cmpnleps(XMMRegister dst, XMMRegister src) {
2815   cmpps(dst, src, 0x6);
2816 }
2817
2818
2819 void Assembler::insertps(XMMRegister dst, XMMRegister src, byte imm8) {
2820   DCHECK(CpuFeatures::IsSupported(SSE4_1));
2821   DCHECK(is_uint8(imm8));
2822   EnsureSpace ensure_space(this);
2823   EMIT(0x66);
2824   EMIT(0x0F);
2825   EMIT(0x3A);
2826   EMIT(0x21);
2827   emit_sse_operand(dst, src);
2828   EMIT(imm8);
2829 }
2830
2831
2832 void Assembler::emit_sse_operand(XMMRegister reg, const Operand& adr) {
2833   Register ireg = { reg.code() };
2834   emit_operand(ireg, adr);
2835 }
2836
2837
2838 void Assembler::emit_sse_operand(XMMRegister dst, XMMRegister src) {
2839   EMIT(0xC0 | dst.code() << 3 | src.code());
2840 }
2841
2842
2843 void Assembler::emit_sse_operand(Register dst, XMMRegister src) {
2844   EMIT(0xC0 | dst.code() << 3 | src.code());
2845 }
2846
2847
2848 void Assembler::emit_sse_operand(XMMRegister dst, Register src) {
2849   EMIT(0xC0 | (dst.code() << 3) | src.code());
2850 }
2851
2852
2853 void Assembler::Print() {
2854   Disassembler::Decode(isolate(), stdout, buffer_, pc_);
2855 }
2856
2857
2858 void Assembler::RecordJSReturn() {
2859   positions_recorder()->WriteRecordedPositions();
2860   EnsureSpace ensure_space(this);
2861   RecordRelocInfo(RelocInfo::JS_RETURN);
2862 }
2863
2864
2865 void Assembler::RecordDebugBreakSlot() {
2866   positions_recorder()->WriteRecordedPositions();
2867   EnsureSpace ensure_space(this);
2868   RecordRelocInfo(RelocInfo::DEBUG_BREAK_SLOT);
2869 }
2870
2871
2872 void Assembler::RecordComment(const char* msg, bool force) {
2873   if (FLAG_code_comments || force) {
2874   EnsureSpace ensure_space(this);
2875     RecordRelocInfo(RelocInfo::COMMENT, reinterpret_cast<intptr_t>(msg));
2876   }
2877 }
2878
2879
2880 void Assembler::GrowBuffer() {
2881   DCHECK(buffer_overflow());
2882   if (!own_buffer_) FATAL("external code buffer is too small");
2883
2884   // Compute new buffer size.
2885   CodeDesc desc;  // the new buffer
2886   desc.buffer_size = 2 * buffer_size_;
2887
2888   // Some internal data structures overflow for very large buffers,
2889   // they must ensure that kMaximalBufferSize is not too large.
2890   if ((desc.buffer_size > kMaximalBufferSize) ||
2891       (desc.buffer_size > isolate()->heap()->MaxOldGenerationSize())) {
2892     V8::FatalProcessOutOfMemory("Assembler::GrowBuffer");
2893   }
2894
2895   // Set up new buffer.
2896   desc.buffer = NewArray<byte>(desc.buffer_size);
2897   desc.instr_size = pc_offset();
2898   desc.reloc_size = (buffer_ + buffer_size_) - (reloc_info_writer.pos());
2899
2900   // Clear the buffer in debug mode. Use 'int3' instructions to make
2901   // sure to get into problems if we ever run uninitialized code.
2902 #ifdef DEBUG
2903   memset(desc.buffer, 0xCC, desc.buffer_size);
2904 #endif
2905
2906   // Copy the data.
2907   int pc_delta = desc.buffer - buffer_;
2908   int rc_delta = (desc.buffer + desc.buffer_size) - (buffer_ + buffer_size_);
2909   MemMove(desc.buffer, buffer_, desc.instr_size);
2910   MemMove(rc_delta + reloc_info_writer.pos(), reloc_info_writer.pos(),
2911           desc.reloc_size);
2912
2913   // Switch buffers.
2914   DeleteArray(buffer_);
2915   buffer_ = desc.buffer;
2916   buffer_size_ = desc.buffer_size;
2917   pc_ += pc_delta;
2918   reloc_info_writer.Reposition(reloc_info_writer.pos() + rc_delta,
2919                                reloc_info_writer.last_pc() + pc_delta);
2920
2921   // Relocate runtime entries.
2922   for (RelocIterator it(desc); !it.done(); it.next()) {
2923     RelocInfo::Mode rmode = it.rinfo()->rmode();
2924     if (rmode == RelocInfo::INTERNAL_REFERENCE) {
2925       int32_t* p = reinterpret_cast<int32_t*>(it.rinfo()->pc());
2926       if (*p != 0) {  // 0 means uninitialized.
2927         *p += pc_delta;
2928       }
2929     }
2930   }
2931
2932   DCHECK(!buffer_overflow());
2933 }
2934
2935
2936 void Assembler::emit_arith_b(int op1, int op2, Register dst, int imm8) {
2937   DCHECK(is_uint8(op1) && is_uint8(op2));  // wrong opcode
2938   DCHECK(is_uint8(imm8));
2939   DCHECK((op1 & 0x01) == 0);  // should be 8bit operation
2940   EMIT(op1);
2941   EMIT(op2 | dst.code());
2942   EMIT(imm8);
2943 }
2944
2945
2946 void Assembler::emit_arith(int sel, Operand dst, const Immediate& x) {
2947   DCHECK((0 <= sel) && (sel <= 7));
2948   Register ireg = { sel };
2949   if (x.is_int8()) {
2950     EMIT(0x83);  // using a sign-extended 8-bit immediate.
2951     emit_operand(ireg, dst);
2952     EMIT(x.x_ & 0xFF);
2953   } else if (dst.is_reg(eax)) {
2954     EMIT((sel << 3) | 0x05);  // short form if the destination is eax.
2955     emit(x);
2956   } else {
2957     EMIT(0x81);  // using a literal 32-bit immediate.
2958     emit_operand(ireg, dst);
2959     emit(x);
2960   }
2961 }
2962
2963
2964 void Assembler::emit_operand(Register reg, const Operand& adr) {
2965   const unsigned length = adr.len_;
2966   DCHECK(length > 0);
2967
2968   // Emit updated ModRM byte containing the given register.
2969   pc_[0] = (adr.buf_[0] & ~0x38) | (reg.code() << 3);
2970
2971   // Emit the rest of the encoded operand.
2972   for (unsigned i = 1; i < length; i++) pc_[i] = adr.buf_[i];
2973   pc_ += length;
2974
2975   // Emit relocation information if necessary.
2976   if (length >= sizeof(int32_t) && !RelocInfo::IsNone(adr.rmode_)) {
2977     pc_ -= sizeof(int32_t);  // pc_ must be *at* disp32
2978     RecordRelocInfo(adr.rmode_);
2979     pc_ += sizeof(int32_t);
2980   }
2981 }
2982
2983
2984 void Assembler::emit_farith(int b1, int b2, int i) {
2985   DCHECK(is_uint8(b1) && is_uint8(b2));  // wrong opcode
2986   DCHECK(0 <= i &&  i < 8);  // illegal stack offset
2987   EMIT(b1);
2988   EMIT(b2 + i);
2989 }
2990
2991
2992 void Assembler::db(uint8_t data) {
2993   EnsureSpace ensure_space(this);
2994   EMIT(data);
2995 }
2996
2997
2998 void Assembler::dd(uint32_t data) {
2999   EnsureSpace ensure_space(this);
3000   emit(data);
3001 }
3002
3003
3004 void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) {
3005   DCHECK(!RelocInfo::IsNone(rmode));
3006   // Don't record external references unless the heap will be serialized.
3007   if (rmode == RelocInfo::EXTERNAL_REFERENCE &&
3008       !serializer_enabled() && !emit_debug_code()) {
3009     return;
3010   }
3011   RelocInfo rinfo(pc_, rmode, data, NULL);
3012   reloc_info_writer.Write(&rinfo);
3013 }
3014
3015
3016 Handle<ConstantPoolArray> Assembler::NewConstantPool(Isolate* isolate) {
3017   // No out-of-line constant pool support.
3018   DCHECK(!FLAG_enable_ool_constant_pool);
3019   return isolate->factory()->empty_constant_pool_array();
3020 }
3021
3022
3023 void Assembler::PopulateConstantPool(ConstantPoolArray* constant_pool) {
3024   // No out-of-line constant pool support.
3025   DCHECK(!FLAG_enable_ool_constant_pool);
3026   return;
3027 }
3028
3029
3030 #ifdef GENERATED_CODE_COVERAGE
3031 static FILE* coverage_log = NULL;
3032
3033
3034 static void InitCoverageLog() {
3035   char* file_name = getenv("V8_GENERATED_CODE_COVERAGE_LOG");
3036   if (file_name != NULL) {
3037     coverage_log = fopen(file_name, "aw+");
3038   }
3039 }
3040
3041
3042 void LogGeneratedCodeCoverage(const char* file_line) {
3043   const char* return_address = (&file_line)[-1];
3044   char* push_insn = const_cast<char*>(return_address - 12);
3045   push_insn[0] = 0xeb;  // Relative branch insn.
3046   push_insn[1] = 13;    // Skip over coverage insns.
3047   if (coverage_log != NULL) {
3048     fprintf(coverage_log, "%s\n", file_line);
3049     fflush(coverage_log);
3050   }
3051 }
3052
3053 #endif
3054
3055 } }  // namespace v8::internal
3056
3057 #endif  // V8_TARGET_ARCH_IA32