assembler_x86.cc revision 1cf95287364948689f6a1a320567acd7728e94a3
12faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes/*
22faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Copyright (C) 2011 The Android Open Source Project
32faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
42faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
52faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * you may not use this file except in compliance with the License.
62faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * You may obtain a copy of the License at
72faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
82faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
92faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
102faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Unless required by applicable law or agreed to in writing, software
112faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
122faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * See the License for the specific language governing permissions and
142faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * limitations under the License.
152faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes */
16a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
172c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers#include "assembler_x86.h"
182c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers
191aa246dec5abe212f699de1413a0c4a191ca364aElliott Hughes#include "base/casts.h"
20166db04e259ca51838c311891598664deeed85adIan Rogers#include "entrypoints/quick/quick_entrypoints.h"
21578bbdc684db8ed68e9fedbc678669d27fa68b6eBrian Carlstrom#include "memory_region.h"
22578bbdc684db8ed68e9fedbc678669d27fa68b6eBrian Carlstrom#include "thread.h"
23547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen#include "utils/dwarf_cfi.h"
24a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
256b6b5f0e67ce03f38223a525612955663bc1799bCarl Shapironamespace art {
262c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersnamespace x86 {
27a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
28b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogersstd::ostream& operator<<(std::ostream& os, const XmmRegister& reg) {
29b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  return os << "XMM" << static_cast<int>(reg);
30b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
31b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
32b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogersstd::ostream& operator<<(std::ostream& os, const X87Register& reg) {
33b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  return os << "ST" << static_cast<int>(reg);
34b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
35a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
362c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::call(Register reg) {
37a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
38a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xFF);
39a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitRegisterOperand(2, reg);
40a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
41a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
42a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
432c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::call(const Address& address) {
44a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
45a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xFF);
46a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(2, address);
47a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
48a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
49a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
502c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::call(Label* label) {
51a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
52a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xE8);
53a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  static const int kSize = 5;
541cf95287364948689f6a1a320567acd7728e94a3Nicolas Geoffray  // Offset by one because we already have emitted the opcode.
551cf95287364948689f6a1a320567acd7728e94a3Nicolas Geoffray  EmitLabel(label, kSize - 1);
56a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
57a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
58a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
598ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffrayvoid X86Assembler::call(const ExternalLabel& label) {
608ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffray  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
618ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffray  intptr_t call_start = buffer_.GetPosition();
628ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffray  EmitUint8(0xE8);
638ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffray  EmitInt32(label.address());
648ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffray  static const intptr_t kCallExternalLabelSize = 5;
658ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffray  DCHECK_EQ((buffer_.GetPosition() - call_start), kCallExternalLabelSize);
668ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffray}
678ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffray
688ccc3f5d06fd217cdaabd37e743adab2031d3720Nicolas Geoffray
692c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::pushl(Register reg) {
70a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
71a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x50 + reg);
72a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
73a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
74a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
752c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::pushl(const Address& address) {
76a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
77a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xFF);
78a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(6, address);
79a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
80a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
81a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
822c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::pushl(const Immediate& imm) {
83a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
8444fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogers  if (imm.is_int8()) {
8544fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogers    EmitUint8(0x6A);
8644fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogers    EmitUint8(imm.value() & 0xFF);
8744fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogers  } else {
8844fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogers    EmitUint8(0x68);
8944fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogers    EmitImmediate(imm);
9044fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogers  }
91a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
92a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
93a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
942c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::popl(Register reg) {
95a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
96a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x58 + reg);
97a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
98a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
99a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1002c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::popl(const Address& address) {
101a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
102a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x8F);
103a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(0, address);
104a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
105a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
106a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1072c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movl(Register dst, const Immediate& imm) {
108a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
109a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xB8 + dst);
110a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitImmediate(imm);
111a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
112a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
113a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1142c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movl(Register dst, Register src) {
115a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
116a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x89);
117a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitRegisterOperand(src, dst);
118a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
119a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
120a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1212c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movl(Register dst, const Address& src) {
122a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
123a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x8B);
124a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, src);
125a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
126a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
127a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1282c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movl(const Address& dst, Register src) {
129a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
130a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x89);
131a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(src, dst);
132a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
133a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
134a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1352c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movl(const Address& dst, const Immediate& imm) {
136a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
137a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xC7);
138a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(0, dst);
139a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitImmediate(imm);
140a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
141a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
142bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogersvoid X86Assembler::movl(const Address& dst, Label* lbl) {
143bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
144bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers  EmitUint8(0xC7);
145bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers  EmitOperand(0, dst);
146bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers  EmitLabel(lbl, dst.length_ + 5);
147bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers}
148a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1492c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movzxb(Register dst, ByteRegister src) {
150a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
151a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
152a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xB6);
153a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitRegisterOperand(dst, src);
154a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
155a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
156a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1572c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movzxb(Register dst, const Address& src) {
158a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
159a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
160a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xB6);
161a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, src);
162a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
163a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
164a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1652c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movsxb(Register dst, ByteRegister src) {
166a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
167a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
168a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xBE);
169a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitRegisterOperand(dst, src);
170a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
171a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
172a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1732c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movsxb(Register dst, const Address& src) {
174a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
175a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
176a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xBE);
177a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, src);
178a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
179a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
180a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1811bac54ffa933fbe9b92b62437577f2f4583eff1aElliott Hughesvoid X86Assembler::movb(Register /*dst*/, const Address& /*src*/) {
182a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  LOG(FATAL) << "Use movzxb or movsxb instead.";
183a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
184a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
185a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1862c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movb(const Address& dst, ByteRegister src) {
187a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
188a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x88);
189a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(src, dst);
190a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
191a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
192a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1932c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movb(const Address& dst, const Immediate& imm) {
194a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
195a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xC6);
196a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(EAX, dst);
197a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  CHECK(imm.is_int8());
198a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(imm.value() & 0xFF);
199a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
200a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
201a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
2022c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movzxw(Register dst, Register src) {
203a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
204a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
205a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xB7);
206a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitRegisterOperand(dst, src);
207a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
208a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
209a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
2102c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movzxw(Register dst, const Address& src) {
211a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
212a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
213a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xB7);
214a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, src);
215a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
216a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
217a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
2182c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movsxw(Register dst, Register src) {
219a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
220a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
221a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xBF);
222a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitRegisterOperand(dst, src);
223a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
224a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
225a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
2262c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movsxw(Register dst, const Address& src) {
227a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
228a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
229a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xBF);
230a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, src);
231a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
232a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
233a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
2341bac54ffa933fbe9b92b62437577f2f4583eff1aElliott Hughesvoid X86Assembler::movw(Register /*dst*/, const Address& /*src*/) {
235a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  LOG(FATAL) << "Use movzxw or movsxw instead.";
236a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
237a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
238a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
2392c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movw(const Address& dst, Register src) {
240a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
241a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperandSizeOverride();
242a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x89);
243a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(src, dst);
244a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
245a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
246a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
24726a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffrayvoid X86Assembler::movw(const Address& dst, const Immediate& imm) {
24826a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
24926a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray  EmitOperandSizeOverride();
25026a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray  EmitUint8(0xC7);
25126a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray  EmitOperand(0, dst);
252b6e7206ad7a426adda9cfd649a4ef969607d79d6Nicolas Geoffray  CHECK(imm.is_uint16() || imm.is_int16());
25326a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray  EmitUint8(imm.value() & 0xFF);
25426a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray  EmitUint8(imm.value() >> 8);
25526a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray}
25626a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray
25726a25ef62a13f409f941aa39825a51b4d6f0f047Nicolas Geoffray
2582c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::leal(Register dst, const Address& src) {
259a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
260a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x8D);
261a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, src);
262a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
263a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
264a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
2652c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::cmovl(Condition condition, Register dst, Register src) {
266a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
267a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
268b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  EmitUint8(0x40 + condition);
269a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitRegisterOperand(dst, src);
270a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
271a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
272a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
2735b4b898ed8725242ee6b7229b94467c3ea3054c8Nicolas Geoffrayvoid X86Assembler::setb(Condition condition, Register dst) {
274a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
275a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
276b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  EmitUint8(0x90 + condition);
2775b4b898ed8725242ee6b7229b94467c3ea3054c8Nicolas Geoffray  EmitOperand(0, Operand(dst));
2787fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray}
2797fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
2807fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray
2817fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffrayvoid X86Assembler::movaps(XmmRegister dst, XmmRegister src) {
2827fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
2837fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  EmitUint8(0x0F);
2847fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  EmitUint8(0x28);
2857fb49da8ec62e8a10ed9419ade9f32c6b1174687Nicolas Geoffray  EmitXmmRegisterOperand(dst, src);
286a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
287a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
288a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
2892c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movss(XmmRegister dst, const Address& src) {
290a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
291a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF3);
292a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
293a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x10);
294a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, src);
295a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
296a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
297a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
2982c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movss(const Address& dst, XmmRegister src) {
299a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
300a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF3);
301a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
302a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x11);
303a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(src, dst);
304a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
305a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
306a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
3072c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movss(XmmRegister dst, XmmRegister src) {
308a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
309a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF3);
310a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
311a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x11);
312a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(src, dst);
313a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
314a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
315a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
3162c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movd(XmmRegister dst, Register src) {
317a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
318a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x66);
319a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
320a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x6E);
321a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, Operand(src));
322a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
323a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
324a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
3252c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movd(Register dst, XmmRegister src) {
326a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
327a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x66);
328a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
329a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x7E);
330a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(src, Operand(dst));
331a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
332a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
333a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
3342c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::addss(XmmRegister dst, XmmRegister src) {
335a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
336a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF3);
337a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
338a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x58);
339a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(dst, src);
340a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
341a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
342a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
3432c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::addss(XmmRegister dst, const Address& src) {
344a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
345a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF3);
346a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
347a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x58);
348a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, src);
349a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
350a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
351a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
3522c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::subss(XmmRegister dst, XmmRegister src) {
353a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
354a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF3);
355a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
356a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x5C);
357a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(dst, src);
358a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
359a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
360a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
3612c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::subss(XmmRegister dst, const Address& src) {
362a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
363a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF3);
364a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
365a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x5C);
366a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, src);
367a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
368a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
369a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
3702c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::mulss(XmmRegister dst, XmmRegister src) {
371a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
372a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF3);
373a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
374a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x59);
375a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(dst, src);
376a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
377a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
378a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
3792c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::mulss(XmmRegister dst, const Address& src) {
380a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
381a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF3);
382a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
383a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x59);
384a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, src);
385a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
386a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
387a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
3882c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::divss(XmmRegister dst, XmmRegister src) {
389a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
390a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF3);
391a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
392a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x5E);
393a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(dst, src);
394a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
395a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
396a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
3972c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::divss(XmmRegister dst, const Address& src) {
398a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
399a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF3);
400a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
401a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x5E);
402a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, src);
403a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
404a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
405a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
4062c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::flds(const Address& src) {
407a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
408a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xD9);
409a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(0, src);
410a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
411a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
412a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
41324f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendellvoid X86Assembler::fsts(const Address& dst) {
41424f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
41524f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell  EmitUint8(0xD9);
41624f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell  EmitOperand(2, dst);
41724f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell}
41824f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell
41924f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell
4202c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::fstps(const Address& dst) {
421a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
422a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xD9);
423a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(3, dst);
424a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
425a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
426a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
4272c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movsd(XmmRegister dst, const Address& src) {
428a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
429a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF2);
430a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
431a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x10);
432a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, src);
433a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
434a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
435a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
4362c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movsd(const Address& dst, XmmRegister src) {
437a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
438a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF2);
439a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
440a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x11);
441a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(src, dst);
442a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
443a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
444a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
4452c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::movsd(XmmRegister dst, XmmRegister src) {
446a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
447a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF2);
448a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
449a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x11);
450a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(src, dst);
451a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
452a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
453a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
45452c489645b6e9ae33623f1ec24143cde5444906eCalin Juravlevoid X86Assembler::psrlq(XmmRegister reg, const Immediate& shift_count) {
45552c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  DCHECK(shift_count.is_uint8());
45652c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle
45752c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
45852c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  EmitUint8(0x66);
45952c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  EmitUint8(0x0F);
46052c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  EmitUint8(0x73);
46152c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  EmitXmmRegisterOperand(2, reg);
46252c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  EmitUint8(shift_count.value());
46352c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle}
46452c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle
46552c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle
46652c489645b6e9ae33623f1ec24143cde5444906eCalin Juravlevoid X86Assembler::punpckldq(XmmRegister dst, XmmRegister src) {
46752c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
46852c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  EmitUint8(0x66);
46952c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  EmitUint8(0x0F);
47052c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  EmitUint8(0x62);
47152c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle  EmitXmmRegisterOperand(dst, src);
47252c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle}
47352c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle
47452c489645b6e9ae33623f1ec24143cde5444906eCalin Juravle
4752c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::addsd(XmmRegister dst, XmmRegister src) {
476a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
477a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF2);
478a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
479a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x58);
480a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(dst, src);
481a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
482a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
483a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
4842c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::addsd(XmmRegister dst, const Address& src) {
485a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
486a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF2);
487a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
488a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x58);
489a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, src);
490a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
491a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
492a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
4932c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::subsd(XmmRegister dst, XmmRegister src) {
494a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
495a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF2);
496a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
497a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x5C);
498a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(dst, src);
499a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
500a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
501a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
5022c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::subsd(XmmRegister dst, const Address& src) {
503a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
504a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF2);
505a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
506a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x5C);
507a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, src);
508a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
509a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
510a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
5112c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::mulsd(XmmRegister dst, XmmRegister src) {
512a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
513a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF2);
514a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
515a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x59);
516a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(dst, src);
517a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
518a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
519a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
5202c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::mulsd(XmmRegister dst, const Address& src) {
521a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
522a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF2);
523a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
524a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x59);
525a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, src);
526a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
527a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
528a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
5292c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::divsd(XmmRegister dst, XmmRegister src) {
530a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
531a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF2);
532a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
533a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x5E);
534a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(dst, src);
535a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
536a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
537a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
5382c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::divsd(XmmRegister dst, const Address& src) {
539a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
540a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF2);
541a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
542a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x5E);
543a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, src);
544a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
545a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
546a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
5472c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::cvtsi2ss(XmmRegister dst, Register src) {
548a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
549a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF3);
550a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
551a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x2A);
552a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, Operand(src));
553a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
554a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
555a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
5562c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::cvtsi2sd(XmmRegister dst, Register src) {
557a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
558a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF2);
559a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
560a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x2A);
561a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, Operand(src));
562a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
563a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
564a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
5652c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::cvtss2si(Register dst, XmmRegister src) {
566a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
567a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF3);
568a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
569a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x2D);
570a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(dst, src);
571a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
572a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
573a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
5742c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::cvtss2sd(XmmRegister dst, XmmRegister src) {
575a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
576a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF3);
577a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
578a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x5A);
579a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(dst, src);
580a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
581a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
582a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
5832c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::cvtsd2si(Register dst, XmmRegister src) {
584a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
585a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF2);
586a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
587a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x2D);
588a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(dst, src);
589a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
590a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
591a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
5922c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::cvttss2si(Register dst, XmmRegister src) {
593a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
594a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF3);
595a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
596a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x2C);
597a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(dst, src);
598a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
599a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
600a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
6012c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::cvttsd2si(Register dst, XmmRegister src) {
602a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
603a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF2);
604a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
605a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x2C);
606a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(dst, src);
607a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
608a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
609a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
6102c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::cvtsd2ss(XmmRegister dst, XmmRegister src) {
611a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
612a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF2);
613a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
614a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x5A);
615a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(dst, src);
616a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
617a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
618a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
6192c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::cvtdq2pd(XmmRegister dst, XmmRegister src) {
620a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
621a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF3);
622a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
623a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xE6);
624a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(dst, src);
625a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
626a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
627a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
6282c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::comiss(XmmRegister a, XmmRegister b) {
629a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
630a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
631a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x2F);
632a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(a, b);
633a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
634a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
635a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
6362c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::comisd(XmmRegister a, XmmRegister b) {
637a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
638a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x66);
639a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
640a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x2F);
641a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(a, b);
642a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
643a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
644a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
645ddb7df25af45d7cd19ed1138e537973735cc78a5Calin Juravlevoid X86Assembler::ucomiss(XmmRegister a, XmmRegister b) {
646ddb7df25af45d7cd19ed1138e537973735cc78a5Calin Juravle  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
647ddb7df25af45d7cd19ed1138e537973735cc78a5Calin Juravle  EmitUint8(0x0F);
648ddb7df25af45d7cd19ed1138e537973735cc78a5Calin Juravle  EmitUint8(0x2E);
649ddb7df25af45d7cd19ed1138e537973735cc78a5Calin Juravle  EmitXmmRegisterOperand(a, b);
650ddb7df25af45d7cd19ed1138e537973735cc78a5Calin Juravle}
651ddb7df25af45d7cd19ed1138e537973735cc78a5Calin Juravle
652ddb7df25af45d7cd19ed1138e537973735cc78a5Calin Juravle
653ddb7df25af45d7cd19ed1138e537973735cc78a5Calin Juravlevoid X86Assembler::ucomisd(XmmRegister a, XmmRegister b) {
654ddb7df25af45d7cd19ed1138e537973735cc78a5Calin Juravle  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
655ddb7df25af45d7cd19ed1138e537973735cc78a5Calin Juravle  EmitUint8(0x66);
656ddb7df25af45d7cd19ed1138e537973735cc78a5Calin Juravle  EmitUint8(0x0F);
657ddb7df25af45d7cd19ed1138e537973735cc78a5Calin Juravle  EmitUint8(0x2E);
658ddb7df25af45d7cd19ed1138e537973735cc78a5Calin Juravle  EmitXmmRegisterOperand(a, b);
659ddb7df25af45d7cd19ed1138e537973735cc78a5Calin Juravle}
660ddb7df25af45d7cd19ed1138e537973735cc78a5Calin Juravle
661ddb7df25af45d7cd19ed1138e537973735cc78a5Calin Juravle
6622c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::sqrtsd(XmmRegister dst, XmmRegister src) {
663a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
664a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF2);
665a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
666a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x51);
667a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(dst, src);
668a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
669a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
670a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
6712c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::sqrtss(XmmRegister dst, XmmRegister src) {
672a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
673a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF3);
674a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
675a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x51);
676a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(dst, src);
677a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
678a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
679a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
6802c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::xorpd(XmmRegister dst, const Address& src) {
681a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
682a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x66);
683a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
684a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x57);
685a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, src);
686a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
687a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
688a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
6892c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::xorpd(XmmRegister dst, XmmRegister src) {
690a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
691a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x66);
692a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
693a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x57);
694a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(dst, src);
695a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
696a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
697a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
6982c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::xorps(XmmRegister dst, const Address& src) {
699a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
700a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
701a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x57);
702a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, src);
703a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
704a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
705a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
7062c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::xorps(XmmRegister dst, XmmRegister src) {
707a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
708a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
709a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x57);
710a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitXmmRegisterOperand(dst, src);
711a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
712a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
713a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
7142c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::andpd(XmmRegister dst, const Address& src) {
715a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
716a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x66);
717a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
718a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x54);
719a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, src);
720a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
721a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
722a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
7232c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::fldl(const Address& src) {
724a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
725a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xDD);
726a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(0, src);
727a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
728a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
729a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
73024f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendellvoid X86Assembler::fstl(const Address& dst) {
73124f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
73224f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell  EmitUint8(0xDD);
73324f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell  EmitOperand(2, dst);
73424f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell}
73524f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell
73624f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell
7372c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::fstpl(const Address& dst) {
738a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
739a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xDD);
740a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(3, dst);
741a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
742a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
743a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
74424f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendellvoid X86Assembler::fstsw() {
74524f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
74624f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell  EmitUint8(0x9B);
74724f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell  EmitUint8(0xDF);
74824f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell  EmitUint8(0xE0);
74924f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell}
75024f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell
75124f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell
7522c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::fnstcw(const Address& dst) {
753a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
754a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xD9);
755a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(7, dst);
756a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
757a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
758a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
7592c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::fldcw(const Address& src) {
760a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
761a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xD9);
762a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(5, src);
763a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
764a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
765a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
7662c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::fistpl(const Address& dst) {
767a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
768a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xDF);
769a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(7, dst);
770a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
771a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
772a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
7732c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::fistps(const Address& dst) {
774a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
775a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xDB);
776a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(3, dst);
777a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
778a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
779a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
7802c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::fildl(const Address& src) {
781a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
782a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xDF);
783a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(5, src);
784a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
785a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
786a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
7872c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::fincstp() {
788a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
789a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xD9);
790a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF7);
791a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
792a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
793a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
7942c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::ffree(const Immediate& index) {
795a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  CHECK_LT(index.value(), 7);
796a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
797a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xDD);
798a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xC0 + index.value());
799a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
800a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
801a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
8022c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::fsin() {
803a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
804a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xD9);
805a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xFE);
806a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
807a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
808a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
8092c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::fcos() {
810a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
811a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xD9);
812a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xFF);
813a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
814a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
815a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
8162c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::fptan() {
817a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
818a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xD9);
819a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF2);
820a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
821a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
822a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
82324f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendellvoid X86Assembler::fucompp() {
82424f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
82524f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell  EmitUint8(0xDA);
82624f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell  EmitUint8(0xE9);
82724f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell}
82824f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell
82924f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell
83024f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendellvoid X86Assembler::fprem() {
83124f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
83224f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell  EmitUint8(0xD9);
83324f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell  EmitUint8(0xF8);
83424f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell}
83524f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell
83624f2dfae084b2382c053f5d688fd6bb26cb8a328Mark Mendell
8372c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::xchgl(Register dst, Register src) {
838a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
839a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x87);
840a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitRegisterOperand(dst, src);
841a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
842a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
8433c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray
8447caad77632ae121c9f64c488e3f8f710e2c4813dIan Rogersvoid X86Assembler::xchgl(Register reg, const Address& address) {
8457caad77632ae121c9f64c488e3f8f710e2c4813dIan Rogers  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
8467caad77632ae121c9f64c488e3f8f710e2c4813dIan Rogers  EmitUint8(0x87);
8477caad77632ae121c9f64c488e3f8f710e2c4813dIan Rogers  EmitOperand(reg, address);
8487caad77632ae121c9f64c488e3f8f710e2c4813dIan Rogers}
8497caad77632ae121c9f64c488e3f8f710e2c4813dIan Rogers
850a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
8513c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffrayvoid X86Assembler::cmpw(const Address& address, const Immediate& imm) {
8523c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
8533c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray  EmitUint8(0x66);
8543c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray  EmitComplex(7, address, imm);
8553c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray}
8563c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray
8573c04974a90b0e03f4b509010bff49f0b2a3da57fNicolas Geoffray
8582c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::cmpl(Register reg, const Immediate& imm) {
859a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
860a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitComplex(7, Operand(reg), imm);
861a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
862a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
863a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
8642c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::cmpl(Register reg0, Register reg1) {
865a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
866a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x3B);
867a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(reg0, Operand(reg1));
868a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
869a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
870a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
8712c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::cmpl(Register reg, const Address& address) {
872a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
873a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x3B);
874a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(reg, address);
875a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
876a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
877a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
8782c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::addl(Register dst, Register src) {
879a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
880a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x03);
881a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitRegisterOperand(dst, src);
882a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
883a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
884a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
8852c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::addl(Register reg, const Address& address) {
886a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
887a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x03);
888a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(reg, address);
889a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
890a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
891a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
8922c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::cmpl(const Address& address, Register reg) {
893a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
894a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x39);
895a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(reg, address);
896a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
897a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
898a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
8992c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::cmpl(const Address& address, const Immediate& imm) {
900a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
901a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitComplex(7, address, imm);
902a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
903a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
904a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
9052c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::testl(Register reg1, Register reg2) {
906a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
907a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x85);
908a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitRegisterOperand(reg1, reg2);
909a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
910a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
911a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
912f12feb8e0e857f2832545b3f28d31bad5a9d3903Nicolas Geoffrayvoid X86Assembler::testl(Register reg, const Address& address) {
913f12feb8e0e857f2832545b3f28d31bad5a9d3903Nicolas Geoffray  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
914f12feb8e0e857f2832545b3f28d31bad5a9d3903Nicolas Geoffray  EmitUint8(0x85);
915f12feb8e0e857f2832545b3f28d31bad5a9d3903Nicolas Geoffray  EmitOperand(reg, address);
916f12feb8e0e857f2832545b3f28d31bad5a9d3903Nicolas Geoffray}
917f12feb8e0e857f2832545b3f28d31bad5a9d3903Nicolas Geoffray
918f12feb8e0e857f2832545b3f28d31bad5a9d3903Nicolas Geoffray
9192c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::testl(Register reg, const Immediate& immediate) {
920a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
921a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  // For registers that have a byte variant (EAX, EBX, ECX, and EDX)
922a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  // we only test the byte register to keep the encoding short.
923a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  if (immediate.is_uint8() && reg < 4) {
924a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    // Use zero-extended 8-bit immediate.
925a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    if (reg == EAX) {
926a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro      EmitUint8(0xA8);
927a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    } else {
928a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro      EmitUint8(0xF6);
929a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro      EmitUint8(0xC0 + reg);
930a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    }
931a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitUint8(immediate.value() & 0xFF);
932a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  } else if (reg == EAX) {
933a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    // Use short form if the destination is EAX.
934a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitUint8(0xA9);
935a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitImmediate(immediate);
936a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  } else {
937a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitUint8(0xF7);
938a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitOperand(0, Operand(reg));
939a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitImmediate(immediate);
940a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  }
941a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
942a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
943a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
9442c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::andl(Register dst, Register src) {
945a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
946a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x23);
947a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, Operand(src));
948a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
949a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
950a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
9519574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffrayvoid X86Assembler::andl(Register reg, const Address& address) {
9529574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
9539574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray  EmitUint8(0x23);
9549574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray  EmitOperand(reg, address);
9559574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray}
9569574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray
9579574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray
9582c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::andl(Register dst, const Immediate& imm) {
959a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
960a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitComplex(4, Operand(dst), imm);
961a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
962a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
963a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
9642c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::orl(Register dst, Register src) {
965a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
966a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0B);
967a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, Operand(src));
968a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
969a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
970a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
9719574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffrayvoid X86Assembler::orl(Register reg, const Address& address) {
9729574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
9739574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray  EmitUint8(0x0B);
9749574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray  EmitOperand(reg, address);
9759574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray}
9769574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray
9779574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray
9782c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::orl(Register dst, const Immediate& imm) {
979a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
980a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitComplex(1, Operand(dst), imm);
981a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
982a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
983a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
9842c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::xorl(Register dst, Register src) {
985a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
986a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x33);
987a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, Operand(src));
988a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
989a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
9909574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray
9919574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffrayvoid X86Assembler::xorl(Register reg, const Address& address) {
9929574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
9939574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray  EmitUint8(0x33);
9949574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray  EmitOperand(reg, address);
9959574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray}
9969574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray
9979574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray
998b55f835d66a61e5da6fc1895ba5a0482868c9552Nicolas Geoffrayvoid X86Assembler::xorl(Register dst, const Immediate& imm) {
999b55f835d66a61e5da6fc1895ba5a0482868c9552Nicolas Geoffray  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1000b55f835d66a61e5da6fc1895ba5a0482868c9552Nicolas Geoffray  EmitComplex(6, Operand(dst), imm);
1001b55f835d66a61e5da6fc1895ba5a0482868c9552Nicolas Geoffray}
1002a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
10039574c4b5f5ef039d694ac12c97e25ca02eca83c0Nicolas Geoffray
10042c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::addl(Register reg, const Immediate& imm) {
1005a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1006a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitComplex(0, Operand(reg), imm);
1007a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1008a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1009a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
10102c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::addl(const Address& address, Register reg) {
1011a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1012a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x01);
1013a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(reg, address);
1014a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1015a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1016a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
10172c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::addl(const Address& address, const Immediate& imm) {
1018a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1019a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitComplex(0, address, imm);
1020a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1021a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1022a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
10232c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::adcl(Register reg, const Immediate& imm) {
1024a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1025a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitComplex(2, Operand(reg), imm);
1026a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1027a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1028a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
10292c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::adcl(Register dst, Register src) {
1030a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1031a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x13);
1032a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, Operand(src));
1033a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1034a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1035a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
10362c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::adcl(Register dst, const Address& address) {
1037a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1038a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x13);
1039a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, address);
1040a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1041a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1042a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
10432c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::subl(Register dst, Register src) {
1044a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1045a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x2B);
1046a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, Operand(src));
1047a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1048a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1049a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
10502c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::subl(Register reg, const Immediate& imm) {
1051a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1052a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitComplex(5, Operand(reg), imm);
1053a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1054a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1055a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
10562c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::subl(Register reg, const Address& address) {
1057a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1058a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x2B);
1059a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(reg, address);
1060a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1061a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1062a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
10632c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::cdq() {
1064a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1065a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x99);
1066a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1067a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1068a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
10692c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::idivl(Register reg) {
1070a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1071a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF7);
1072a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF8 | reg);
1073a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1074a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1075a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
10762c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::imull(Register dst, Register src) {
1077a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1078a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
1079a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xAF);
1080a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, Operand(src));
1081a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1082a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1083a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
10842c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::imull(Register reg, const Immediate& imm) {
1085a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1086a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x69);
1087a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(reg, Operand(reg));
1088a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitImmediate(imm);
1089a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1090a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1091a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
10922c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::imull(Register reg, const Address& address) {
1093a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1094a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
1095a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xAF);
1096a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(reg, address);
1097a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1098a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1099a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
11002c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::imull(Register reg) {
1101a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1102a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF7);
1103a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(5, Operand(reg));
1104a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1105a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1106a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
11072c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::imull(const Address& address) {
1108a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1109a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF7);
1110a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(5, address);
1111a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1112a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1113a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
11142c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::mull(Register reg) {
1115a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1116a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF7);
1117a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(4, Operand(reg));
1118a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1119a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1120a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
11212c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::mull(const Address& address) {
1122a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1123a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF7);
1124a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(4, address);
1125a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1126a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1127a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
11282c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::sbbl(Register dst, Register src) {
1129a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1130a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x1B);
1131a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, Operand(src));
1132a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1133a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1134a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
11352c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::sbbl(Register reg, const Immediate& imm) {
1136a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1137a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitComplex(3, Operand(reg), imm);
1138a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1139a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1140a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
11412c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::sbbl(Register dst, const Address& address) {
1142a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1143a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x1B);
1144a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(dst, address);
1145a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1146a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1147a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
11482c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::incl(Register reg) {
1149a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1150a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x40 + reg);
1151a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1152a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1153a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
11542c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::incl(const Address& address) {
1155a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1156a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xFF);
1157a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(0, address);
1158a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1159a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1160a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
11612c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::decl(Register reg) {
1162a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1163a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x48 + reg);
1164a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1165a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1166a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
11672c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::decl(const Address& address) {
1168a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1169a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xFF);
1170a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(1, address);
1171a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1172a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1173a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
11742c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::shll(Register reg, const Immediate& imm) {
1175a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitGenericShift(4, reg, imm);
1176a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1177a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1178a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
11792c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::shll(Register operand, Register shifter) {
1180a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitGenericShift(4, operand, shifter);
1181a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1182a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1183a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
11842c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::shrl(Register reg, const Immediate& imm) {
1185a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitGenericShift(5, reg, imm);
1186a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1187a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1188a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
11892c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::shrl(Register operand, Register shifter) {
1190a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitGenericShift(5, operand, shifter);
1191a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1192a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1193a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
11942c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::sarl(Register reg, const Immediate& imm) {
1195a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitGenericShift(7, reg, imm);
1196a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1197a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1198a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
11992c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::sarl(Register operand, Register shifter) {
1200a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitGenericShift(7, operand, shifter);
1201a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1202a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1203a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
12049aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravlevoid X86Assembler::shld(Register dst, Register src, Register shifter) {
12059aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle  DCHECK_EQ(ECX, shifter);
1206a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1207a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
1208a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xA5);
1209a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitRegisterOperand(src, dst);
1210a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1211a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1212a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
12139aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravlevoid X86Assembler::shrd(Register dst, Register src, Register shifter) {
12149aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle  DCHECK_EQ(ECX, shifter);
12159aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
12169aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle  EmitUint8(0x0F);
12179aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle  EmitUint8(0xAD);
12189aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle  EmitRegisterOperand(src, dst);
12199aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle}
12209aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle
12219aec02fc5df5518c16f1e5a9b6cb198a192db973Calin Juravle
12222c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::negl(Register reg) {
1223a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1224a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF7);
1225a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(3, Operand(reg));
1226a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1227a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1228a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
12292c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::notl(Register reg) {
1230a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1231a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF7);
1232a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xD0 | reg);
1233a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1234a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1235a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
12362c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::enter(const Immediate& imm) {
1237a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1238a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xC8);
1239a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  CHECK(imm.is_uint16());
1240a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(imm.value() & 0xFF);
1241a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8((imm.value() >> 8) & 0xFF);
1242a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x00);
1243a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1244a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1245a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
12462c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::leave() {
1247a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1248a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xC9);
1249a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1250a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1251a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
12522c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::ret() {
1253a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1254a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xC3);
1255a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1256a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1257a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
12582c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::ret(const Immediate& imm) {
1259a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1260a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xC2);
1261a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  CHECK(imm.is_uint16());
1262a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(imm.value() & 0xFF);
1263a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8((imm.value() >> 8) & 0xFF);
1264a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1265a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1266a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1267a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
12682c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::nop() {
1269a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1270a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x90);
1271a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1272a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1273a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
12742c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::int3() {
1275a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1276a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xCC);
1277a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1278a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1279a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
12802c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::hlt() {
1281a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1282a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF4);
1283a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1284a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1285a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
12862c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::j(Condition condition, Label* label) {
1287a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1288a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  if (label->IsBound()) {
1289a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    static const int kShortSize = 2;
1290a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    static const int kLongSize = 6;
1291a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    int offset = label->Position() - buffer_.Size();
1292a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    CHECK_LE(offset, 0);
1293a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    if (IsInt(8, offset - kShortSize)) {
1294a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro      EmitUint8(0x70 + condition);
1295a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro      EmitUint8((offset - kShortSize) & 0xFF);
1296a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    } else {
1297a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro      EmitUint8(0x0F);
1298a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro      EmitUint8(0x80 + condition);
1299a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro      EmitInt32(offset - kLongSize);
1300a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    }
1301a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  } else {
1302a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitUint8(0x0F);
1303a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitUint8(0x80 + condition);
1304a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitLabelLink(label);
1305a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  }
1306a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1307a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1308a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
13092c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::jmp(Register reg) {
1310a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1311a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xFF);
1312a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitRegisterOperand(4, reg);
1313a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1314a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
13157caad77632ae121c9f64c488e3f8f710e2c4813dIan Rogersvoid X86Assembler::jmp(const Address& address) {
13167caad77632ae121c9f64c488e3f8f710e2c4813dIan Rogers  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
13177caad77632ae121c9f64c488e3f8f710e2c4813dIan Rogers  EmitUint8(0xFF);
13187caad77632ae121c9f64c488e3f8f710e2c4813dIan Rogers  EmitOperand(4, address);
13197caad77632ae121c9f64c488e3f8f710e2c4813dIan Rogers}
1320a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
13212c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::jmp(Label* label) {
1322a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1323a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  if (label->IsBound()) {
1324a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    static const int kShortSize = 2;
1325a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    static const int kLongSize = 5;
1326a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    int offset = label->Position() - buffer_.Size();
1327a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    CHECK_LE(offset, 0);
1328a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    if (IsInt(8, offset - kShortSize)) {
1329a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro      EmitUint8(0xEB);
1330a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro      EmitUint8((offset - kShortSize) & 0xFF);
1331a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    } else {
1332a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro      EmitUint8(0xE9);
1333a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro      EmitInt32(offset - kLongSize);
1334a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    }
1335a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  } else {
1336a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitUint8(0xE9);
1337a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitLabelLink(label);
1338a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  }
1339a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1340a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1341a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
13422c8f653c98d658419f464b6147c10e11a664d2e6Ian RogersX86Assembler* X86Assembler::lock() {
1343a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1344a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xF0);
13450d666d8769714dcbc2acc4dd5b06f0deffa6e0a1Ian Rogers  return this;
1346a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1347a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1348a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
13492c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::cmpxchgl(const Address& address, Register reg) {
1350a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1351a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0x0F);
1352a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xB1);
1353a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitOperand(reg, address);
1354a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1355a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
135679ab9e32c6880e7b342c192a479c858c9dccf496Elliott Hughesvoid X86Assembler::mfence() {
135779ab9e32c6880e7b342c192a479c858c9dccf496Elliott Hughes  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
135879ab9e32c6880e7b342c192a479c858c9dccf496Elliott Hughes  EmitUint8(0x0F);
135979ab9e32c6880e7b342c192a479c858c9dccf496Elliott Hughes  EmitUint8(0xAE);
136079ab9e32c6880e7b342c192a479c858c9dccf496Elliott Hughes  EmitUint8(0xF0);
136179ab9e32c6880e7b342c192a479c858c9dccf496Elliott Hughes}
136279ab9e32c6880e7b342c192a479c858c9dccf496Elliott Hughes
13632c8f653c98d658419f464b6147c10e11a664d2e6Ian RogersX86Assembler* X86Assembler::fs() {
1364b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  // TODO: fs is a prefix and not an instruction
1365b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1366b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  EmitUint8(0x64);
13670d666d8769714dcbc2acc4dd5b06f0deffa6e0a1Ian Rogers  return this;
1368b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1369a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1370befbd5731ecca08f08780ee28a913d08ffb14656Ian RogersX86Assembler* X86Assembler::gs() {
1371befbd5731ecca08f08780ee28a913d08ffb14656Ian Rogers  // TODO: fs is a prefix and not an instruction
1372befbd5731ecca08f08780ee28a913d08ffb14656Ian Rogers  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1373befbd5731ecca08f08780ee28a913d08ffb14656Ian Rogers  EmitUint8(0x65);
1374befbd5731ecca08f08780ee28a913d08ffb14656Ian Rogers  return this;
1375befbd5731ecca08f08780ee28a913d08ffb14656Ian Rogers}
1376befbd5731ecca08f08780ee28a913d08ffb14656Ian Rogers
13772c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::AddImmediate(Register reg, const Immediate& imm) {
1378a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  int value = imm.value();
1379a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  if (value > 0) {
1380a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    if (value == 1) {
1381a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro      incl(reg);
1382a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    } else if (value != 0) {
1383a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro      addl(reg, imm);
1384a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    }
1385a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  } else if (value < 0) {
1386a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    value = -value;
1387a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    if (value == 1) {
1388a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro      decl(reg);
1389a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    } else if (value != 0) {
1390a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro      subl(reg, Immediate(value));
1391a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    }
1392a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  }
1393a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1394a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1395a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1396647b9ed41cdb7cf302fd356627a3ba372419b78cRoland Levillainvoid X86Assembler::LoadLongConstant(XmmRegister dst, int64_t value) {
1397647b9ed41cdb7cf302fd356627a3ba372419b78cRoland Levillain  // TODO: Need to have a code constants table.
1398647b9ed41cdb7cf302fd356627a3ba372419b78cRoland Levillain  pushl(Immediate(High32Bits(value)));
1399647b9ed41cdb7cf302fd356627a3ba372419b78cRoland Levillain  pushl(Immediate(Low32Bits(value)));
1400647b9ed41cdb7cf302fd356627a3ba372419b78cRoland Levillain  movsd(dst, Address(ESP, 0));
1401647b9ed41cdb7cf302fd356627a3ba372419b78cRoland Levillain  addl(ESP, Immediate(2 * sizeof(int32_t)));
1402647b9ed41cdb7cf302fd356627a3ba372419b78cRoland Levillain}
1403647b9ed41cdb7cf302fd356627a3ba372419b78cRoland Levillain
1404647b9ed41cdb7cf302fd356627a3ba372419b78cRoland Levillain
14052c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::LoadDoubleConstant(XmmRegister dst, double value) {
1406a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  // TODO: Need to have a code constants table.
1407a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  int64_t constant = bit_cast<int64_t, double>(value);
1408647b9ed41cdb7cf302fd356627a3ba372419b78cRoland Levillain  LoadLongConstant(dst, constant);
1409a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1410a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1411a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
14122c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::Align(int alignment, int offset) {
1413a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  CHECK(IsPowerOfTwo(alignment));
1414a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  // Emit nop instruction until the real position is aligned.
1415a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  while (((offset + buffer_.GetPosition()) & (alignment-1)) != 0) {
1416a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    nop();
1417a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  }
1418a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1419a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1420a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
14212c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::Bind(Label* label) {
1422a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  int bound = buffer_.Size();
1423a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  CHECK(!label->IsBound());  // Labels can only be bound once.
1424a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  while (label->IsLinked()) {
1425a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    int position = label->LinkPosition();
1426a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    int next = buffer_.Load<int32_t>(position);
1427a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    buffer_.Store<int32_t>(position, bound - (position + 4));
1428a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    label->position_ = next;
1429a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  }
1430a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  label->BindTo(bound);
1431a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1432a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1433a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
143444fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogersvoid X86Assembler::EmitOperand(int reg_or_opcode, const Operand& operand) {
143544fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogers  CHECK_GE(reg_or_opcode, 0);
143644fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogers  CHECK_LT(reg_or_opcode, 8);
1437a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  const int length = operand.length_;
1438a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  CHECK_GT(length, 0);
143944fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogers  // Emit the ModRM byte updated with the given reg value.
1440a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  CHECK_EQ(operand.encoding_[0] & 0x38, 0);
144144fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogers  EmitUint8(operand.encoding_[0] + (reg_or_opcode << 3));
1442a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  // Emit the rest of the encoded operand.
1443a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  for (int i = 1; i < length; i++) {
1444a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitUint8(operand.encoding_[i]);
1445a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  }
1446a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1447a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1448a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
14492c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::EmitImmediate(const Immediate& imm) {
1450a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitInt32(imm.value());
1451a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1452a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1453a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
145444fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogersvoid X86Assembler::EmitComplex(int reg_or_opcode,
14552c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                               const Operand& operand,
14562c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                               const Immediate& immediate) {
145744fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogers  CHECK_GE(reg_or_opcode, 0);
145844fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogers  CHECK_LT(reg_or_opcode, 8);
1459a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  if (immediate.is_int8()) {
1460a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    // Use sign-extended 8-bit immediate.
1461a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitUint8(0x83);
146244fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogers    EmitOperand(reg_or_opcode, operand);
1463a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitUint8(immediate.value() & 0xFF);
1464a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  } else if (operand.IsRegister(EAX)) {
1465a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    // Use short form if the destination is eax.
146644fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogers    EmitUint8(0x05 + (reg_or_opcode << 3));
1467a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitImmediate(immediate);
1468a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  } else {
1469a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitUint8(0x81);
147044fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogers    EmitOperand(reg_or_opcode, operand);
1471a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitImmediate(immediate);
1472a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  }
1473a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1474a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1475a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
14762c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::EmitLabel(Label* label, int instruction_size) {
1477a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  if (label->IsBound()) {
1478a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    int offset = label->Position() - buffer_.Size();
1479a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    CHECK_LE(offset, 0);
1480a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitInt32(offset - instruction_size);
1481a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  } else {
1482a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitLabelLink(label);
1483a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  }
1484a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1485a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1486a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
14872c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::EmitLabelLink(Label* label) {
1488a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  CHECK(!label->IsBound());
1489a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  int position = buffer_.Size();
1490a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitInt32(label->position_);
1491a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  label->LinkTo(position);
1492a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1493a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1494a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
149544fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogersvoid X86Assembler::EmitGenericShift(int reg_or_opcode,
14962c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                                    Register reg,
14972c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                                    const Immediate& imm) {
1498a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1499a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  CHECK(imm.is_int8());
1500a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  if (imm.value() == 1) {
1501a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitUint8(0xD1);
150244fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogers    EmitOperand(reg_or_opcode, Operand(reg));
1503a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  } else {
1504a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitUint8(0xC1);
150544fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogers    EmitOperand(reg_or_opcode, Operand(reg));
1506a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro    EmitUint8(imm.value() & 0xFF);
1507a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  }
1508a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1509a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1510a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
151144fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogersvoid X86Assembler::EmitGenericShift(int reg_or_opcode,
15122c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                                    Register operand,
15132c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                                    Register shifter) {
1514a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1515a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  CHECK_EQ(shifter, ECX);
1516a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro  EmitUint8(0xD3);
151744fb0d0e096067e6bfe1dbfedf369e705bb10814Ian Rogers  EmitOperand(reg_or_opcode, Operand(operand));
1518a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro}
1519a5d5cfda6239d8876937e75eba43222f639d2447Carl Shapiro
1520547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shenvoid X86Assembler::InitializeFrameDescriptionEntry() {
1521e3ea83811d47152c00abea24a9b420651a33b496Yevgeny Rouban  WriteFDEHeader(&cfi_info_, false /* is_64bit */);
1522547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen}
1523547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen
1524547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shenvoid X86Assembler::FinalizeFrameDescriptionEntry() {
1525e3ea83811d47152c00abea24a9b420651a33b496Yevgeny Rouban  WriteFDEAddressRange(&cfi_info_, buffer_.Size(), false /* is_64bit */);
1526547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  PadCFI(&cfi_info_);
1527e3ea83811d47152c00abea24a9b420651a33b496Yevgeny Rouban  WriteCFILength(&cfi_info_, false /* is_64bit */);
1528547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen}
1529547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen
1530790a6b7312979513710c366b411ba6791ddf78c2Ian Rogersconstexpr size_t kFramePointerSize = 4;
1531790a6b7312979513710c366b411ba6791ddf78c2Ian Rogers
15322c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::BuildFrame(size_t frame_size, ManagedRegister method_reg,
1533b5d09b2f87202bc132ac3991d4b6d71f4f6d9264Ian Rogers                              const std::vector<ManagedRegister>& spill_regs,
1534fca82208f7128fcda09b6a4743199308332558a2Dmitry Petrochenko                              const ManagedRegisterEntrySpills& entry_spills) {
1535547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  cfi_cfa_offset_ = kFramePointerSize;  // Only return address on stack
1536547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  cfi_pc_ = buffer_.Size();  // Nothing emitted yet
1537547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  DCHECK_EQ(cfi_pc_, 0U);
1538547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen
1539547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  uint32_t reg_offset = 1;
154006b37d91bb3d543002b1aee9829691f5e8bebc7eElliott Hughes  CHECK_ALIGNED(frame_size, kStackAlignment);
1541966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell  int gpr_count = 0;
1542703f2cd1f4d1eb5ab5c9792ca2de9ffb39378203jeffhao  for (int i = spill_regs.size() - 1; i >= 0; --i) {
1543966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell    x86::X86ManagedRegister spill = spill_regs.at(i).AsX86();
1544966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell    DCHECK(spill.IsCpuRegister());
1545966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell    pushl(spill.AsCpuRegister());
1546966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell    gpr_count++;
1547547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen
1548547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen    // DW_CFA_advance_loc
1549547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen    DW_CFA_advance_loc(&cfi_info_, buffer_.Size() - cfi_pc_);
1550547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen    cfi_pc_ = buffer_.Size();
1551547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen    // DW_CFA_def_cfa_offset
1552547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen    cfi_cfa_offset_ += kFramePointerSize;
1553547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen    DW_CFA_def_cfa_offset(&cfi_info_, cfi_cfa_offset_);
1554547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen    // DW_CFA_offset reg offset
1555547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen    reg_offset++;
1556547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen    DW_CFA_offset(&cfi_info_, spill_regs.at(i).AsX86().DWARFRegId(), reg_offset);
1557703f2cd1f4d1eb5ab5c9792ca2de9ffb39378203jeffhao  }
1558547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen
1559b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  // return address then method on stack
1560966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell  int32_t adjust = frame_size - (gpr_count * kFramePointerSize) -
1561547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen                   sizeof(StackReference<mirror::ArtMethod>) /*method*/ -
1562547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen                   kFramePointerSize /*return address*/;
1563547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  addl(ESP, Immediate(-adjust));
1564547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  // DW_CFA_advance_loc
1565547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  DW_CFA_advance_loc(&cfi_info_, buffer_.Size() - cfi_pc_);
1566547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  cfi_pc_ = buffer_.Size();
1567547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  // DW_CFA_def_cfa_offset
1568547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  cfi_cfa_offset_ += adjust;
1569547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  DW_CFA_def_cfa_offset(&cfi_info_, cfi_cfa_offset_);
1570547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen
15712c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  pushl(method_reg.AsX86().AsCpuRegister());
1572547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  // DW_CFA_advance_loc
1573547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  DW_CFA_advance_loc(&cfi_info_, buffer_.Size() - cfi_pc_);
1574547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  cfi_pc_ = buffer_.Size();
1575547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  // DW_CFA_def_cfa_offset
1576547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  cfi_cfa_offset_ += kFramePointerSize;
1577547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  DW_CFA_def_cfa_offset(&cfi_info_, cfi_cfa_offset_);
1578547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen
1579b5d09b2f87202bc132ac3991d4b6d71f4f6d9264Ian Rogers  for (size_t i = 0; i < entry_spills.size(); ++i) {
1580966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell    ManagedRegisterSpill spill = entry_spills.at(i);
1581966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell    if (spill.AsX86().IsCpuRegister()) {
1582966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell      movl(Address(ESP, frame_size + spill.getSpillOffset()), spill.AsX86().AsCpuRegister());
1583966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell    } else {
1584966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell      DCHECK(spill.AsX86().IsXmmRegister());
1585966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell      if (spill.getSize() == 8) {
1586966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell        movsd(Address(ESP, frame_size + spill.getSpillOffset()), spill.AsX86().AsXmmRegister());
1587966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell      } else {
1588966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell        CHECK_EQ(spill.getSize(), 4);
1589966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell        movss(Address(ESP, frame_size + spill.getSpillOffset()), spill.AsX86().AsXmmRegister());
1590966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell      }
1591966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell    }
1592b5d09b2f87202bc132ac3991d4b6d71f4f6d9264Ian Rogers  }
1593b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1594b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
15952c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::RemoveFrame(size_t frame_size,
15960d666d8769714dcbc2acc4dd5b06f0deffa6e0a1Ian Rogers                            const std::vector<ManagedRegister>& spill_regs) {
159706b37d91bb3d543002b1aee9829691f5e8bebc7eElliott Hughes  CHECK_ALIGNED(frame_size, kStackAlignment);
1598cf4035a4c41ccfcc3e89a0cee25f5218a11b0705Andreas Gampe  addl(ESP, Immediate(frame_size - (spill_regs.size() * kFramePointerSize) -
1599cf4035a4c41ccfcc3e89a0cee25f5218a11b0705Andreas Gampe                      sizeof(StackReference<mirror::ArtMethod>)));
1600703f2cd1f4d1eb5ab5c9792ca2de9ffb39378203jeffhao  for (size_t i = 0; i < spill_regs.size(); ++i) {
1601966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell    x86::X86ManagedRegister spill = spill_regs.at(i).AsX86();
1602966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell    DCHECK(spill.IsCpuRegister());
1603966c3ae95d3c699ee9fbdbccc1acdaaf02325fafMark P Mendell    popl(spill.AsCpuRegister());
1604703f2cd1f4d1eb5ab5c9792ca2de9ffb39378203jeffhao  }
1605b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  ret();
1606b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1607b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
16082c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::IncreaseFrameSize(size_t adjust) {
160906b37d91bb3d543002b1aee9829691f5e8bebc7eElliott Hughes  CHECK_ALIGNED(adjust, kStackAlignment);
1610b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  addl(ESP, Immediate(-adjust));
1611547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  // DW_CFA_advance_loc
1612547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  DW_CFA_advance_loc(&cfi_info_, buffer_.Size() - cfi_pc_);
1613547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  cfi_pc_ = buffer_.Size();
1614547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  // DW_CFA_def_cfa_offset
1615547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  cfi_cfa_offset_ += adjust;
1616547cdfd21ee21e4ab9ca8692d6ef47c62ee7ea52Tong Shen  DW_CFA_def_cfa_offset(&cfi_info_, cfi_cfa_offset_);
1617b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1618b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
16192c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::DecreaseFrameSize(size_t adjust) {
162006b37d91bb3d543002b1aee9829691f5e8bebc7eElliott Hughes  CHECK_ALIGNED(adjust, kStackAlignment);
1621b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  addl(ESP, Immediate(adjust));
1622b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1623b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
16242c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::Store(FrameOffset offs, ManagedRegister msrc, size_t size) {
16252c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister src = msrc.AsX86();
162645a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers  if (src.IsNoRegister()) {
162745a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers    CHECK_EQ(0u, size);
162845a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers  } else if (src.IsCpuRegister()) {
1629b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    CHECK_EQ(4u, size);
1630b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    movl(Address(ESP, offs), src.AsCpuRegister());
16319b269d281d16798b0c24027c32ec6507f71b2787Ian Rogers  } else if (src.IsRegisterPair()) {
16329b269d281d16798b0c24027c32ec6507f71b2787Ian Rogers    CHECK_EQ(8u, size);
16339b269d281d16798b0c24027c32ec6507f71b2787Ian Rogers    movl(Address(ESP, offs), src.AsRegisterPairLow());
16349b269d281d16798b0c24027c32ec6507f71b2787Ian Rogers    movl(Address(ESP, FrameOffset(offs.Int32Value()+4)),
16359b269d281d16798b0c24027c32ec6507f71b2787Ian Rogers         src.AsRegisterPairHigh());
163645a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers  } else if (src.IsX87Register()) {
163745a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers    if (size == 4) {
163845a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers      fstps(Address(ESP, offs));
163945a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers    } else {
164045a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers      fstpl(Address(ESP, offs));
164145a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers    }
164245a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers  } else {
164345a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers    CHECK(src.IsXmmRegister());
1644b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    if (size == 4) {
1645b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers      movss(Address(ESP, offs), src.AsXmmRegister());
1646b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    } else {
1647b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers      movsd(Address(ESP, offs), src.AsXmmRegister());
1648b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    }
1649b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  }
1650b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1651b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
16522c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::StoreRef(FrameOffset dest, ManagedRegister msrc) {
16532c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister src = msrc.AsX86();
1654b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  CHECK(src.IsCpuRegister());
1655b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  movl(Address(ESP, dest), src.AsCpuRegister());
1656b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1657b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
16582c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::StoreRawPtr(FrameOffset dest, ManagedRegister msrc) {
16592c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister src = msrc.AsX86();
1660df20fe0c097073f75f22d16e72fd3636a31d3ca1Ian Rogers  CHECK(src.IsCpuRegister());
1661df20fe0c097073f75f22d16e72fd3636a31d3ca1Ian Rogers  movl(Address(ESP, dest), src.AsCpuRegister());
1662df20fe0c097073f75f22d16e72fd3636a31d3ca1Ian Rogers}
1663df20fe0c097073f75f22d16e72fd3636a31d3ca1Ian Rogers
16642c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::StoreImmediateToFrame(FrameOffset dest, uint32_t imm,
16652c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                                         ManagedRegister) {
16662c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  movl(Address(ESP, dest), Immediate(imm));
16672c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers}
16682c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers
1669dd7624d2b9e599d57762d12031b10b89defc9807Ian Rogersvoid X86Assembler::StoreImmediateToThread32(ThreadOffset<4> dest, uint32_t imm,
16702c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                                          ManagedRegister) {
16712c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  fs()->movl(Address::Absolute(dest), Immediate(imm));
16722c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers}
16732c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers
1674dd7624d2b9e599d57762d12031b10b89defc9807Ian Rogersvoid X86Assembler::StoreStackOffsetToThread32(ThreadOffset<4> thr_offs,
16752c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                                            FrameOffset fr_offs,
16762c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                                            ManagedRegister mscratch) {
16772c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister scratch = mscratch.AsX86();
1678b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  CHECK(scratch.IsCpuRegister());
16792c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  leal(scratch.AsCpuRegister(), Address(ESP, fr_offs));
16802c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  fs()->movl(Address::Absolute(thr_offs), scratch.AsCpuRegister());
1681b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1682b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
1683dd7624d2b9e599d57762d12031b10b89defc9807Ian Rogersvoid X86Assembler::StoreStackPointerToThread32(ThreadOffset<4> thr_offs) {
16842c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  fs()->movl(Address::Absolute(thr_offs), ESP);
1685b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1686b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
16871bac54ffa933fbe9b92b62437577f2f4583eff1aElliott Hughesvoid X86Assembler::StoreSpanning(FrameOffset /*dst*/, ManagedRegister /*src*/,
16881bac54ffa933fbe9b92b62437577f2f4583eff1aElliott Hughes                                 FrameOffset /*in_off*/, ManagedRegister /*scratch*/) {
16892c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  UNIMPLEMENTED(FATAL);  // this case only currently exists for ARM
1690b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1691b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
16922c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::Load(ManagedRegister mdest, FrameOffset src, size_t size) {
16932c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister dest = mdest.AsX86();
169445a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers  if (dest.IsNoRegister()) {
169545a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers    CHECK_EQ(0u, size);
169645a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers  } else if (dest.IsCpuRegister()) {
1697b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    CHECK_EQ(4u, size);
1698b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    movl(dest.AsCpuRegister(), Address(ESP, src));
16999b269d281d16798b0c24027c32ec6507f71b2787Ian Rogers  } else if (dest.IsRegisterPair()) {
17009b269d281d16798b0c24027c32ec6507f71b2787Ian Rogers    CHECK_EQ(8u, size);
17019b269d281d16798b0c24027c32ec6507f71b2787Ian Rogers    movl(dest.AsRegisterPairLow(), Address(ESP, src));
17029b269d281d16798b0c24027c32ec6507f71b2787Ian Rogers    movl(dest.AsRegisterPairHigh(), Address(ESP, FrameOffset(src.Int32Value()+4)));
170345a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers  } else if (dest.IsX87Register()) {
170445a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers    if (size == 4) {
170545a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers      flds(Address(ESP, src));
170645a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers    } else {
170745a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers      fldl(Address(ESP, src));
170845a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers    }
1709b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  } else {
171045a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers    CHECK(dest.IsXmmRegister());
171145a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers    if (size == 4) {
171245a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers      movss(dest.AsXmmRegister(), Address(ESP, src));
171345a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers    } else {
171445a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers      movsd(dest.AsXmmRegister(), Address(ESP, src));
171545a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers    }
1716b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  }
1717b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1718b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
1719dd7624d2b9e599d57762d12031b10b89defc9807Ian Rogersvoid X86Assembler::LoadFromThread32(ManagedRegister mdest, ThreadOffset<4> src, size_t size) {
17205a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers  X86ManagedRegister dest = mdest.AsX86();
17215a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers  if (dest.IsNoRegister()) {
17225a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers    CHECK_EQ(0u, size);
17235a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers  } else if (dest.IsCpuRegister()) {
17245a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers    CHECK_EQ(4u, size);
17255a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers    fs()->movl(dest.AsCpuRegister(), Address::Absolute(src));
17265a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers  } else if (dest.IsRegisterPair()) {
17275a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers    CHECK_EQ(8u, size);
17285a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers    fs()->movl(dest.AsRegisterPairLow(), Address::Absolute(src));
1729dd7624d2b9e599d57762d12031b10b89defc9807Ian Rogers    fs()->movl(dest.AsRegisterPairHigh(), Address::Absolute(ThreadOffset<4>(src.Int32Value()+4)));
17305a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers  } else if (dest.IsX87Register()) {
17315a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers    if (size == 4) {
17325a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers      fs()->flds(Address::Absolute(src));
17335a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers    } else {
17345a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers      fs()->fldl(Address::Absolute(src));
17355a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers    }
17365a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers  } else {
17375a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers    CHECK(dest.IsXmmRegister());
17385a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers    if (size == 4) {
17395a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers      fs()->movss(dest.AsXmmRegister(), Address::Absolute(src));
17405a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers    } else {
17415a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers      fs()->movsd(dest.AsXmmRegister(), Address::Absolute(src));
17425a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers    }
17435a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers  }
17445a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers}
17455a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers
17462c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::LoadRef(ManagedRegister mdest, FrameOffset  src) {
17472c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister dest = mdest.AsX86();
1748b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  CHECK(dest.IsCpuRegister());
1749b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  movl(dest.AsCpuRegister(), Address(ESP, src));
1750b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1751b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
17522c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::LoadRef(ManagedRegister mdest, ManagedRegister base,
17532c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                           MemberOffset offs) {
17542c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister dest = mdest.AsX86();
1755b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  CHECK(dest.IsCpuRegister() && dest.IsCpuRegister());
17562c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  movl(dest.AsCpuRegister(), Address(base.AsX86().AsCpuRegister(), offs));
1757e63a745f26fec5a5b4162fc83f6e88a1f696c30cHiroshi Yamauchi  if (kPoisonHeapReferences) {
1758e63a745f26fec5a5b4162fc83f6e88a1f696c30cHiroshi Yamauchi    negl(dest.AsCpuRegister());
1759e63a745f26fec5a5b4162fc83f6e88a1f696c30cHiroshi Yamauchi  }
1760a04d397b990ee7d3ce120e317c19fb4409d80d57Ian Rogers}
1761a04d397b990ee7d3ce120e317c19fb4409d80d57Ian Rogers
17622c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::LoadRawPtr(ManagedRegister mdest, ManagedRegister base,
17632c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                              Offset offs) {
17642c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister dest = mdest.AsX86();
1765a04d397b990ee7d3ce120e317c19fb4409d80d57Ian Rogers  CHECK(dest.IsCpuRegister() && dest.IsCpuRegister());
17662c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  movl(dest.AsCpuRegister(), Address(base.AsX86().AsCpuRegister(), offs));
1767b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1768b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
1769dd7624d2b9e599d57762d12031b10b89defc9807Ian Rogersvoid X86Assembler::LoadRawPtrFromThread32(ManagedRegister mdest,
1770dd7624d2b9e599d57762d12031b10b89defc9807Ian Rogers                                        ThreadOffset<4> offs) {
17712c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister dest = mdest.AsX86();
1772b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  CHECK(dest.IsCpuRegister());
17730d666d8769714dcbc2acc4dd5b06f0deffa6e0a1Ian Rogers  fs()->movl(dest.AsCpuRegister(), Address::Absolute(offs));
1774b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1775b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
177658136caeec7cb677bb83c2eafd1f4bab5afd96c8jeffhaovoid X86Assembler::SignExtend(ManagedRegister mreg, size_t size) {
177758136caeec7cb677bb83c2eafd1f4bab5afd96c8jeffhao  X86ManagedRegister reg = mreg.AsX86();
177858136caeec7cb677bb83c2eafd1f4bab5afd96c8jeffhao  CHECK(size == 1 || size == 2) << size;
177958136caeec7cb677bb83c2eafd1f4bab5afd96c8jeffhao  CHECK(reg.IsCpuRegister()) << reg;
178058136caeec7cb677bb83c2eafd1f4bab5afd96c8jeffhao  if (size == 1) {
178158136caeec7cb677bb83c2eafd1f4bab5afd96c8jeffhao    movsxb(reg.AsCpuRegister(), reg.AsByteRegister());
178258136caeec7cb677bb83c2eafd1f4bab5afd96c8jeffhao  } else {
178358136caeec7cb677bb83c2eafd1f4bab5afd96c8jeffhao    movsxw(reg.AsCpuRegister(), reg.AsCpuRegister());
178458136caeec7cb677bb83c2eafd1f4bab5afd96c8jeffhao  }
178558136caeec7cb677bb83c2eafd1f4bab5afd96c8jeffhao}
178658136caeec7cb677bb83c2eafd1f4bab5afd96c8jeffhao
1787cee4d0c1c2faacf0eae748a24cc7e455e067d977jeffhaovoid X86Assembler::ZeroExtend(ManagedRegister mreg, size_t size) {
1788cee4d0c1c2faacf0eae748a24cc7e455e067d977jeffhao  X86ManagedRegister reg = mreg.AsX86();
1789cee4d0c1c2faacf0eae748a24cc7e455e067d977jeffhao  CHECK(size == 1 || size == 2) << size;
1790cee4d0c1c2faacf0eae748a24cc7e455e067d977jeffhao  CHECK(reg.IsCpuRegister()) << reg;
1791cee4d0c1c2faacf0eae748a24cc7e455e067d977jeffhao  if (size == 1) {
1792cee4d0c1c2faacf0eae748a24cc7e455e067d977jeffhao    movzxb(reg.AsCpuRegister(), reg.AsByteRegister());
1793cee4d0c1c2faacf0eae748a24cc7e455e067d977jeffhao  } else {
1794cee4d0c1c2faacf0eae748a24cc7e455e067d977jeffhao    movzxw(reg.AsCpuRegister(), reg.AsCpuRegister());
1795cee4d0c1c2faacf0eae748a24cc7e455e067d977jeffhao  }
1796cee4d0c1c2faacf0eae748a24cc7e455e067d977jeffhao}
1797cee4d0c1c2faacf0eae748a24cc7e455e067d977jeffhao
1798b5d09b2f87202bc132ac3991d4b6d71f4f6d9264Ian Rogersvoid X86Assembler::Move(ManagedRegister mdest, ManagedRegister msrc, size_t size) {
17992c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister dest = mdest.AsX86();
18002c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister src = msrc.AsX86();
18012c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  if (!dest.Equals(src)) {
18022c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers    if (dest.IsCpuRegister() && src.IsCpuRegister()) {
18032c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers      movl(dest.AsCpuRegister(), src.AsCpuRegister());
1804b5d09b2f87202bc132ac3991d4b6d71f4f6d9264Ian Rogers    } else if (src.IsX87Register() && dest.IsXmmRegister()) {
1805b5d09b2f87202bc132ac3991d4b6d71f4f6d9264Ian Rogers      // Pass via stack and pop X87 register
1806b5d09b2f87202bc132ac3991d4b6d71f4f6d9264Ian Rogers      subl(ESP, Immediate(16));
1807b5d09b2f87202bc132ac3991d4b6d71f4f6d9264Ian Rogers      if (size == 4) {
1808b5d09b2f87202bc132ac3991d4b6d71f4f6d9264Ian Rogers        CHECK_EQ(src.AsX87Register(), ST0);
1809b5d09b2f87202bc132ac3991d4b6d71f4f6d9264Ian Rogers        fstps(Address(ESP, 0));
1810b5d09b2f87202bc132ac3991d4b6d71f4f6d9264Ian Rogers        movss(dest.AsXmmRegister(), Address(ESP, 0));
1811b5d09b2f87202bc132ac3991d4b6d71f4f6d9264Ian Rogers      } else {
1812b5d09b2f87202bc132ac3991d4b6d71f4f6d9264Ian Rogers        CHECK_EQ(src.AsX87Register(), ST0);
1813b5d09b2f87202bc132ac3991d4b6d71f4f6d9264Ian Rogers        fstpl(Address(ESP, 0));
1814b5d09b2f87202bc132ac3991d4b6d71f4f6d9264Ian Rogers        movsd(dest.AsXmmRegister(), Address(ESP, 0));
1815b5d09b2f87202bc132ac3991d4b6d71f4f6d9264Ian Rogers      }
1816b5d09b2f87202bc132ac3991d4b6d71f4f6d9264Ian Rogers      addl(ESP, Immediate(16));
18172c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers    } else {
18182c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers      // TODO: x87, SSE
18192c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers      UNIMPLEMENTED(FATAL) << ": Move " << dest << ", " << src;
18202c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers    }
18212c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  }
1822b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1823b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
18242c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::CopyRef(FrameOffset dest, FrameOffset src,
18252c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                           ManagedRegister mscratch) {
18262c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister scratch = mscratch.AsX86();
1827b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  CHECK(scratch.IsCpuRegister());
18282c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  movl(scratch.AsCpuRegister(), Address(ESP, src));
18292c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  movl(Address(ESP, dest), scratch.AsCpuRegister());
1830b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1831b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
1832dd7624d2b9e599d57762d12031b10b89defc9807Ian Rogersvoid X86Assembler::CopyRawPtrFromThread32(FrameOffset fr_offs,
1833dd7624d2b9e599d57762d12031b10b89defc9807Ian Rogers                                        ThreadOffset<4> thr_offs,
18342c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                                        ManagedRegister mscratch) {
18352c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister scratch = mscratch.AsX86();
1836b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  CHECK(scratch.IsCpuRegister());
18372c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  fs()->movl(scratch.AsCpuRegister(), Address::Absolute(thr_offs));
18382c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  Store(fr_offs, scratch, 4);
183945a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers}
184045a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers
1841dd7624d2b9e599d57762d12031b10b89defc9807Ian Rogersvoid X86Assembler::CopyRawPtrToThread32(ThreadOffset<4> thr_offs,
18422c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                                      FrameOffset fr_offs,
18432c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                                      ManagedRegister mscratch) {
18442c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister scratch = mscratch.AsX86();
18452c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  CHECK(scratch.IsCpuRegister());
18462c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  Load(scratch, fr_offs, 4);
18472c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  fs()->movl(Address::Absolute(thr_offs), scratch.AsCpuRegister());
1848b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1849b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
18502c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::Copy(FrameOffset dest, FrameOffset src,
18512c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                        ManagedRegister mscratch,
18522c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                        size_t size) {
18532c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister scratch = mscratch.AsX86();
1854b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  if (scratch.IsCpuRegister() && size == 8) {
1855b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    Load(scratch, src, 4);
1856b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    Store(dest, scratch, 4);
1857b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    Load(scratch, FrameOffset(src.Int32Value() + 4), 4);
1858b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    Store(FrameOffset(dest.Int32Value() + 4), scratch, 4);
1859b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  } else {
1860b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    Load(scratch, src, size);
1861b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    Store(dest, scratch, size);
1862b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  }
1863b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1864b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
18651bac54ffa933fbe9b92b62437577f2f4583eff1aElliott Hughesvoid X86Assembler::Copy(FrameOffset /*dst*/, ManagedRegister /*src_base*/, Offset /*src_offset*/,
18661bac54ffa933fbe9b92b62437577f2f4583eff1aElliott Hughes                        ManagedRegister /*scratch*/, size_t /*size*/) {
1867dc51b79e65abcdad094ccd5e5a2caf5153433d49Ian Rogers  UNIMPLEMENTED(FATAL);
1868dc51b79e65abcdad094ccd5e5a2caf5153433d49Ian Rogers}
1869dc51b79e65abcdad094ccd5e5a2caf5153433d49Ian Rogers
18705a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogersvoid X86Assembler::Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src,
18715a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers                        ManagedRegister scratch, size_t size) {
18725a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers  CHECK(scratch.IsNoRegister());
18735a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers  CHECK_EQ(size, 4u);
18745a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers  pushl(Address(ESP, src));
18755a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers  popl(Address(dest_base.AsX86().AsCpuRegister(), dest_offset));
18765a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers}
18775a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers
1878dc51b79e65abcdad094ccd5e5a2caf5153433d49Ian Rogersvoid X86Assembler::Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset,
1879dc51b79e65abcdad094ccd5e5a2caf5153433d49Ian Rogers                        ManagedRegister mscratch, size_t size) {
1880dc51b79e65abcdad094ccd5e5a2caf5153433d49Ian Rogers  Register scratch = mscratch.AsX86().AsCpuRegister();
1881dc51b79e65abcdad094ccd5e5a2caf5153433d49Ian Rogers  CHECK_EQ(size, 4u);
1882dc51b79e65abcdad094ccd5e5a2caf5153433d49Ian Rogers  movl(scratch, Address(ESP, src_base));
1883dc51b79e65abcdad094ccd5e5a2caf5153433d49Ian Rogers  movl(scratch, Address(scratch, src_offset));
1884dc51b79e65abcdad094ccd5e5a2caf5153433d49Ian Rogers  movl(Address(ESP, dest), scratch);
1885dc51b79e65abcdad094ccd5e5a2caf5153433d49Ian Rogers}
1886dc51b79e65abcdad094ccd5e5a2caf5153433d49Ian Rogers
18875a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogersvoid X86Assembler::Copy(ManagedRegister dest, Offset dest_offset,
18885a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers                        ManagedRegister src, Offset src_offset,
18895a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers                        ManagedRegister scratch, size_t size) {
18905a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers  CHECK_EQ(size, 4u);
18915a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers  CHECK(scratch.IsNoRegister());
18925a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers  pushl(Address(src.AsX86().AsCpuRegister(), src_offset));
18935a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers  popl(Address(dest.AsX86().AsCpuRegister(), dest_offset));
18945a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers}
18955a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers
18965a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogersvoid X86Assembler::Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset,
18975a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers                        ManagedRegister mscratch, size_t size) {
1898dc51b79e65abcdad094ccd5e5a2caf5153433d49Ian Rogers  Register scratch = mscratch.AsX86().AsCpuRegister();
1899dc51b79e65abcdad094ccd5e5a2caf5153433d49Ian Rogers  CHECK_EQ(size, 4u);
19005a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers  CHECK_EQ(dest.Int32Value(), src.Int32Value());
19015a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers  movl(scratch, Address(ESP, src));
19025a7a74a042e73a355f5cedffa0d2faf5340028faIan Rogers  pushl(Address(scratch, src_offset));
1903dc51b79e65abcdad094ccd5e5a2caf5153433d49Ian Rogers  popl(Address(scratch, dest_offset));
1904dc51b79e65abcdad094ccd5e5a2caf5153433d49Ian Rogers}
1905dc51b79e65abcdad094ccd5e5a2caf5153433d49Ian Rogers
1906e5de95b3f9609e02fefd7cda7b21f30c9412eb4cIan Rogersvoid X86Assembler::MemoryBarrier(ManagedRegister) {
190779ab9e32c6880e7b342c192a479c858c9dccf496Elliott Hughes  mfence();
1908e5de95b3f9609e02fefd7cda7b21f30c9412eb4cIan Rogers}
1909e5de95b3f9609e02fefd7cda7b21f30c9412eb4cIan Rogers
1910eb8167a4f4d27fce0530f6724ab8032610cd146bMathieu Chartiervoid X86Assembler::CreateHandleScopeEntry(ManagedRegister mout_reg,
1911eb8167a4f4d27fce0530f6724ab8032610cd146bMathieu Chartier                                   FrameOffset handle_scope_offset,
19122c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                                   ManagedRegister min_reg, bool null_allowed) {
19132c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister out_reg = mout_reg.AsX86();
19142c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister in_reg = min_reg.AsX86();
1915b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  CHECK(in_reg.IsCpuRegister());
1916b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  CHECK(out_reg.IsCpuRegister());
1917408f79aeb676251ba35667a64e86c20638d7cb0bIan Rogers  VerifyObject(in_reg, null_allowed);
1918b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  if (null_allowed) {
1919b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    Label null_arg;
1920b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    if (!out_reg.Equals(in_reg)) {
1921b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers      xorl(out_reg.AsCpuRegister(), out_reg.AsCpuRegister());
1922b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    }
1923b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    testl(in_reg.AsCpuRegister(), in_reg.AsCpuRegister());
192418c0753c1659629021b4becdaa3f6ea81aecce35Elliott Hughes    j(kZero, &null_arg);
1925eb8167a4f4d27fce0530f6724ab8032610cd146bMathieu Chartier    leal(out_reg.AsCpuRegister(), Address(ESP, handle_scope_offset));
1926b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    Bind(&null_arg);
1927b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  } else {
1928eb8167a4f4d27fce0530f6724ab8032610cd146bMathieu Chartier    leal(out_reg.AsCpuRegister(), Address(ESP, handle_scope_offset));
1929b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  }
1930b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1931b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
1932eb8167a4f4d27fce0530f6724ab8032610cd146bMathieu Chartiervoid X86Assembler::CreateHandleScopeEntry(FrameOffset out_off,
1933eb8167a4f4d27fce0530f6724ab8032610cd146bMathieu Chartier                                   FrameOffset handle_scope_offset,
19342c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                                   ManagedRegister mscratch,
19352c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                                   bool null_allowed) {
19362c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister scratch = mscratch.AsX86();
1937b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  CHECK(scratch.IsCpuRegister());
1938b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  if (null_allowed) {
1939b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    Label null_arg;
1940eb8167a4f4d27fce0530f6724ab8032610cd146bMathieu Chartier    movl(scratch.AsCpuRegister(), Address(ESP, handle_scope_offset));
1941b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    testl(scratch.AsCpuRegister(), scratch.AsCpuRegister());
194218c0753c1659629021b4becdaa3f6ea81aecce35Elliott Hughes    j(kZero, &null_arg);
1943eb8167a4f4d27fce0530f6724ab8032610cd146bMathieu Chartier    leal(scratch.AsCpuRegister(), Address(ESP, handle_scope_offset));
1944b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    Bind(&null_arg);
1945b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  } else {
1946eb8167a4f4d27fce0530f6724ab8032610cd146bMathieu Chartier    leal(scratch.AsCpuRegister(), Address(ESP, handle_scope_offset));
1947b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  }
1948b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  Store(out_off, scratch, 4);
1949b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1950b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
1951eb8167a4f4d27fce0530f6724ab8032610cd146bMathieu Chartier// Given a handle scope entry, load the associated reference.
1952eb8167a4f4d27fce0530f6724ab8032610cd146bMathieu Chartiervoid X86Assembler::LoadReferenceFromHandleScope(ManagedRegister mout_reg,
19532c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                                         ManagedRegister min_reg) {
19542c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister out_reg = mout_reg.AsX86();
19552c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister in_reg = min_reg.AsX86();
1956b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  CHECK(out_reg.IsCpuRegister());
1957b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  CHECK(in_reg.IsCpuRegister());
1958b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  Label null_arg;
1959b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  if (!out_reg.Equals(in_reg)) {
1960b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers    xorl(out_reg.AsCpuRegister(), out_reg.AsCpuRegister());
1961b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  }
1962b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  testl(in_reg.AsCpuRegister(), in_reg.AsCpuRegister());
196318c0753c1659629021b4becdaa3f6ea81aecce35Elliott Hughes  j(kZero, &null_arg);
1964b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  movl(out_reg.AsCpuRegister(), Address(in_reg.AsCpuRegister(), 0));
1965b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  Bind(&null_arg);
1966b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1967b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
19681bac54ffa933fbe9b92b62437577f2f4583eff1aElliott Hughesvoid X86Assembler::VerifyObject(ManagedRegister /*src*/, bool /*could_be_null*/) {
1969b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  // TODO: not validating references
1970b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1971b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
19721bac54ffa933fbe9b92b62437577f2f4583eff1aElliott Hughesvoid X86Assembler::VerifyObject(FrameOffset /*src*/, bool /*could_be_null*/) {
1973b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  // TODO: not validating references
1974b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1975b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
19762c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::Call(ManagedRegister mbase, Offset offset, ManagedRegister) {
19772c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister base = mbase.AsX86();
1978b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  CHECK(base.IsCpuRegister());
1979df20fe0c097073f75f22d16e72fd3636a31d3ca1Ian Rogers  call(Address(base.AsCpuRegister(), offset.Int32Value()));
1980b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers  // TODO: place reference map on call
1981b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}
1982b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers
198367375acd9fec74cc2054554fe1ed0a7d213e1e47Ian Rogersvoid X86Assembler::Call(FrameOffset base, Offset offset, ManagedRegister mscratch) {
198467375acd9fec74cc2054554fe1ed0a7d213e1e47Ian Rogers  Register scratch = mscratch.AsX86().AsCpuRegister();
198567375acd9fec74cc2054554fe1ed0a7d213e1e47Ian Rogers  movl(scratch, Address(ESP, base));
198667375acd9fec74cc2054554fe1ed0a7d213e1e47Ian Rogers  call(Address(scratch, offset));
1987e2d373e6e09c1df9a47e73a26254048adb31ce82Carl Shapiro}
1988e2d373e6e09c1df9a47e73a26254048adb31ce82Carl Shapiro
1989dd7624d2b9e599d57762d12031b10b89defc9807Ian Rogersvoid X86Assembler::CallFromThread32(ThreadOffset<4> offset, ManagedRegister /*mscratch*/) {
1990bdb0391258abc54bf77c676e36847d28a783bfe5Ian Rogers  fs()->call(Address::Absolute(offset));
1991668512afd0d9b3772a0abc589208b729ee16bc61Shih-wei Liao}
1992668512afd0d9b3772a0abc589208b729ee16bc61Shih-wei Liao
19932c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::GetCurrentThread(ManagedRegister tr) {
19942c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  fs()->movl(tr.AsX86().AsCpuRegister(),
1995dd7624d2b9e599d57762d12031b10b89defc9807Ian Rogers             Address::Absolute(Thread::SelfOffset<4>()));
1996668512afd0d9b3772a0abc589208b729ee16bc61Shih-wei Liao}
1997668512afd0d9b3772a0abc589208b729ee16bc61Shih-wei Liao
19982c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86Assembler::GetCurrentThread(FrameOffset offset,
19992c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers                                    ManagedRegister mscratch) {
20002c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86ManagedRegister scratch = mscratch.AsX86();
2001dd7624d2b9e599d57762d12031b10b89defc9807Ian Rogers  fs()->movl(scratch.AsCpuRegister(), Address::Absolute(Thread::SelfOffset<4>()));
2002668512afd0d9b3772a0abc589208b729ee16bc61Shih-wei Liao  movl(Address(ESP, offset), scratch.AsCpuRegister());
2003668512afd0d9b3772a0abc589208b729ee16bc61Shih-wei Liao}
2004668512afd0d9b3772a0abc589208b729ee16bc61Shih-wei Liao
200500f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogersvoid X86Assembler::ExceptionPoll(ManagedRegister /*scratch*/, size_t stack_adjust) {
200600f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  X86ExceptionSlowPath* slow = new X86ExceptionSlowPath(stack_adjust);
200745a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers  buffer_.EnqueueSlowPath(slow);
2008dd7624d2b9e599d57762d12031b10b89defc9807Ian Rogers  fs()->cmpl(Address::Absolute(Thread::ExceptionOffset<4>()), Immediate(0));
200918c0753c1659629021b4becdaa3f6ea81aecce35Elliott Hughes  j(kNotEqual, slow->Entry());
201045a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers}
20110d666d8769714dcbc2acc4dd5b06f0deffa6e0a1Ian Rogers
20122c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogersvoid X86ExceptionSlowPath::Emit(Assembler *sasm) {
20132c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers  X86Assembler* sp_asm = down_cast<X86Assembler*>(sasm);
20140d666d8769714dcbc2acc4dd5b06f0deffa6e0a1Ian Rogers#define __ sp_asm->
20150d666d8769714dcbc2acc4dd5b06f0deffa6e0a1Ian Rogers  __ Bind(&entry_);
201620cde9033d51103f31e21436e88f80e1170c78adElliott Hughes  // Note: the return value is dead
201700f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  if (stack_adjust_ != 0) {  // Fix up the frame.
201800f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers    __ DecreaseFrameSize(stack_adjust_);
201900f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  }
202067375acd9fec74cc2054554fe1ed0a7d213e1e47Ian Rogers  // Pass exception as argument in EAX
2021dd7624d2b9e599d57762d12031b10b89defc9807Ian Rogers  __ fs()->movl(EAX, Address::Absolute(Thread::ExceptionOffset<4>()));
2022dd7624d2b9e599d57762d12031b10b89defc9807Ian Rogers  __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(4, pDeliverException)));
202367375acd9fec74cc2054554fe1ed0a7d213e1e47Ian Rogers  // this call should never return
202467375acd9fec74cc2054554fe1ed0a7d213e1e47Ian Rogers  __ int3();
20250d666d8769714dcbc2acc4dd5b06f0deffa6e0a1Ian Rogers#undef __
202645a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers}
202745a76cb99104a222d6a9bd768a084893dcb7cf30Ian Rogers
20282c8f653c98d658419f464b6147c10e11a664d2e6Ian Rogers}  // namespace x86
2029b033c75ebda80ac75f936366fe78d1edf5cec937Ian Rogers}  // namespace art
2030