blob: 3ff24b7a2731ff12557227120ff7ad82e71385ef [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070016
Ian Rogers2c8f6532011-09-02 17:16:34 -070017#include "assembler_x86.h"
18
Elliott Hughes1aa246d2012-12-13 09:29:36 -080019#include "base/casts.h"
Ian Rogers166db042013-07-26 12:05:57 -070020#include "entrypoints/quick/quick_entrypoints.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070021#include "memory_region.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070022#include "thread.h"
Tong Shen547cdfd2014-08-05 01:54:19 -070023#include "utils/dwarf_cfi.h"
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070024
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070025namespace art {
Ian Rogers2c8f6532011-09-02 17:16:34 -070026namespace x86 {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070027
Ian Rogersb033c752011-07-20 12:22:35 -070028std::ostream& operator<<(std::ostream& os, const XmmRegister& reg) {
29 return os << "XMM" << static_cast<int>(reg);
30}
31
32std::ostream& operator<<(std::ostream& os, const X87Register& reg) {
33 return os << "ST" << static_cast<int>(reg);
34}
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070035
Ian Rogers2c8f6532011-09-02 17:16:34 -070036void X86Assembler::call(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070037 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
38 EmitUint8(0xFF);
39 EmitRegisterOperand(2, reg);
40}
41
42
Ian Rogers2c8f6532011-09-02 17:16:34 -070043void X86Assembler::call(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070044 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
45 EmitUint8(0xFF);
46 EmitOperand(2, address);
47}
48
49
Ian Rogers2c8f6532011-09-02 17:16:34 -070050void X86Assembler::call(Label* label) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070051 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
52 EmitUint8(0xE8);
53 static const int kSize = 5;
54 EmitLabel(label, kSize);
55}
56
57
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000058void X86Assembler::call(const ExternalLabel& label) {
59 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
60 intptr_t call_start = buffer_.GetPosition();
61 EmitUint8(0xE8);
62 EmitInt32(label.address());
63 static const intptr_t kCallExternalLabelSize = 5;
64 DCHECK_EQ((buffer_.GetPosition() - call_start), kCallExternalLabelSize);
65}
66
67
Ian Rogers2c8f6532011-09-02 17:16:34 -070068void X86Assembler::pushl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070069 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
70 EmitUint8(0x50 + reg);
71}
72
73
Ian Rogers2c8f6532011-09-02 17:16:34 -070074void X86Assembler::pushl(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070075 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
76 EmitUint8(0xFF);
77 EmitOperand(6, address);
78}
79
80
Ian Rogers2c8f6532011-09-02 17:16:34 -070081void X86Assembler::pushl(const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070082 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
Ian Rogers44fb0d02012-03-23 16:46:24 -070083 if (imm.is_int8()) {
84 EmitUint8(0x6A);
85 EmitUint8(imm.value() & 0xFF);
86 } else {
87 EmitUint8(0x68);
88 EmitImmediate(imm);
89 }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070090}
91
92
Ian Rogers2c8f6532011-09-02 17:16:34 -070093void X86Assembler::popl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070094 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
95 EmitUint8(0x58 + reg);
96}
97
98
Ian Rogers2c8f6532011-09-02 17:16:34 -070099void X86Assembler::popl(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700100 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
101 EmitUint8(0x8F);
102 EmitOperand(0, address);
103}
104
105
Ian Rogers2c8f6532011-09-02 17:16:34 -0700106void X86Assembler::movl(Register dst, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700107 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
108 EmitUint8(0xB8 + dst);
109 EmitImmediate(imm);
110}
111
112
Ian Rogers2c8f6532011-09-02 17:16:34 -0700113void X86Assembler::movl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700114 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
115 EmitUint8(0x89);
116 EmitRegisterOperand(src, dst);
117}
118
119
Ian Rogers2c8f6532011-09-02 17:16:34 -0700120void X86Assembler::movl(Register dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700121 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
122 EmitUint8(0x8B);
123 EmitOperand(dst, src);
124}
125
126
Ian Rogers2c8f6532011-09-02 17:16:34 -0700127void X86Assembler::movl(const Address& dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700128 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
129 EmitUint8(0x89);
130 EmitOperand(src, dst);
131}
132
133
Ian Rogers2c8f6532011-09-02 17:16:34 -0700134void X86Assembler::movl(const Address& dst, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700135 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
136 EmitUint8(0xC7);
137 EmitOperand(0, dst);
138 EmitImmediate(imm);
139}
140
Ian Rogersbdb03912011-09-14 00:55:44 -0700141void X86Assembler::movl(const Address& dst, Label* lbl) {
142 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
143 EmitUint8(0xC7);
144 EmitOperand(0, dst);
145 EmitLabel(lbl, dst.length_ + 5);
146}
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700147
Ian Rogers2c8f6532011-09-02 17:16:34 -0700148void X86Assembler::movzxb(Register dst, ByteRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700149 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
150 EmitUint8(0x0F);
151 EmitUint8(0xB6);
152 EmitRegisterOperand(dst, src);
153}
154
155
Ian Rogers2c8f6532011-09-02 17:16:34 -0700156void X86Assembler::movzxb(Register dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700157 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
158 EmitUint8(0x0F);
159 EmitUint8(0xB6);
160 EmitOperand(dst, src);
161}
162
163
Ian Rogers2c8f6532011-09-02 17:16:34 -0700164void X86Assembler::movsxb(Register dst, ByteRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700165 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
166 EmitUint8(0x0F);
167 EmitUint8(0xBE);
168 EmitRegisterOperand(dst, src);
169}
170
171
Ian Rogers2c8f6532011-09-02 17:16:34 -0700172void X86Assembler::movsxb(Register dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700173 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
174 EmitUint8(0x0F);
175 EmitUint8(0xBE);
176 EmitOperand(dst, src);
177}
178
179
Elliott Hughes1bac54f2012-03-16 12:48:31 -0700180void X86Assembler::movb(Register /*dst*/, const Address& /*src*/) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700181 LOG(FATAL) << "Use movzxb or movsxb instead.";
182}
183
184
Ian Rogers2c8f6532011-09-02 17:16:34 -0700185void X86Assembler::movb(const Address& dst, ByteRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700186 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
187 EmitUint8(0x88);
188 EmitOperand(src, dst);
189}
190
191
Ian Rogers2c8f6532011-09-02 17:16:34 -0700192void X86Assembler::movb(const Address& dst, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700193 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
194 EmitUint8(0xC6);
195 EmitOperand(EAX, dst);
196 CHECK(imm.is_int8());
197 EmitUint8(imm.value() & 0xFF);
198}
199
200
Ian Rogers2c8f6532011-09-02 17:16:34 -0700201void X86Assembler::movzxw(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700202 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
203 EmitUint8(0x0F);
204 EmitUint8(0xB7);
205 EmitRegisterOperand(dst, src);
206}
207
208
Ian Rogers2c8f6532011-09-02 17:16:34 -0700209void X86Assembler::movzxw(Register dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700210 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
211 EmitUint8(0x0F);
212 EmitUint8(0xB7);
213 EmitOperand(dst, src);
214}
215
216
Ian Rogers2c8f6532011-09-02 17:16:34 -0700217void X86Assembler::movsxw(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700218 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
219 EmitUint8(0x0F);
220 EmitUint8(0xBF);
221 EmitRegisterOperand(dst, src);
222}
223
224
Ian Rogers2c8f6532011-09-02 17:16:34 -0700225void X86Assembler::movsxw(Register dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700226 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
227 EmitUint8(0x0F);
228 EmitUint8(0xBF);
229 EmitOperand(dst, src);
230}
231
232
Elliott Hughes1bac54f2012-03-16 12:48:31 -0700233void X86Assembler::movw(Register /*dst*/, const Address& /*src*/) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700234 LOG(FATAL) << "Use movzxw or movsxw instead.";
235}
236
237
Ian Rogers2c8f6532011-09-02 17:16:34 -0700238void X86Assembler::movw(const Address& dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700239 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
240 EmitOperandSizeOverride();
241 EmitUint8(0x89);
242 EmitOperand(src, dst);
243}
244
245
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +0100246void X86Assembler::movw(const Address& dst, const Immediate& imm) {
247 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
248 EmitOperandSizeOverride();
249 EmitUint8(0xC7);
250 EmitOperand(0, dst);
Nicolas Geoffrayb6e72062014-10-07 14:54:48 +0100251 CHECK(imm.is_uint16() || imm.is_int16());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +0100252 EmitUint8(imm.value() & 0xFF);
253 EmitUint8(imm.value() >> 8);
254}
255
256
Ian Rogers2c8f6532011-09-02 17:16:34 -0700257void X86Assembler::leal(Register dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700258 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
259 EmitUint8(0x8D);
260 EmitOperand(dst, src);
261}
262
263
Ian Rogers2c8f6532011-09-02 17:16:34 -0700264void X86Assembler::cmovl(Condition condition, Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700265 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
266 EmitUint8(0x0F);
Ian Rogersb033c752011-07-20 12:22:35 -0700267 EmitUint8(0x40 + condition);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700268 EmitRegisterOperand(dst, src);
269}
270
271
Ian Rogers2c8f6532011-09-02 17:16:34 -0700272void X86Assembler::setb(Condition condition, Register dst) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700273 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
274 EmitUint8(0x0F);
Ian Rogersb033c752011-07-20 12:22:35 -0700275 EmitUint8(0x90 + condition);
276 EmitOperand(0, Operand(dst));
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700277}
278
279
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100280void X86Assembler::movaps(XmmRegister dst, XmmRegister src) {
281 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
282 EmitUint8(0x0F);
283 EmitUint8(0x28);
284 EmitXmmRegisterOperand(dst, src);
285}
286
287
Ian Rogers2c8f6532011-09-02 17:16:34 -0700288void X86Assembler::movss(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700289 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
290 EmitUint8(0xF3);
291 EmitUint8(0x0F);
292 EmitUint8(0x10);
293 EmitOperand(dst, src);
294}
295
296
Ian Rogers2c8f6532011-09-02 17:16:34 -0700297void X86Assembler::movss(const Address& dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700298 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
299 EmitUint8(0xF3);
300 EmitUint8(0x0F);
301 EmitUint8(0x11);
302 EmitOperand(src, dst);
303}
304
305
Ian Rogers2c8f6532011-09-02 17:16:34 -0700306void X86Assembler::movss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700307 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
308 EmitUint8(0xF3);
309 EmitUint8(0x0F);
310 EmitUint8(0x11);
311 EmitXmmRegisterOperand(src, dst);
312}
313
314
Ian Rogers2c8f6532011-09-02 17:16:34 -0700315void X86Assembler::movd(XmmRegister dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700316 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
317 EmitUint8(0x66);
318 EmitUint8(0x0F);
319 EmitUint8(0x6E);
320 EmitOperand(dst, Operand(src));
321}
322
323
Ian Rogers2c8f6532011-09-02 17:16:34 -0700324void X86Assembler::movd(Register dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700325 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
326 EmitUint8(0x66);
327 EmitUint8(0x0F);
328 EmitUint8(0x7E);
329 EmitOperand(src, Operand(dst));
330}
331
332
Ian Rogers2c8f6532011-09-02 17:16:34 -0700333void X86Assembler::addss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700334 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
335 EmitUint8(0xF3);
336 EmitUint8(0x0F);
337 EmitUint8(0x58);
338 EmitXmmRegisterOperand(dst, src);
339}
340
341
Ian Rogers2c8f6532011-09-02 17:16:34 -0700342void X86Assembler::addss(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700343 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
344 EmitUint8(0xF3);
345 EmitUint8(0x0F);
346 EmitUint8(0x58);
347 EmitOperand(dst, src);
348}
349
350
Ian Rogers2c8f6532011-09-02 17:16:34 -0700351void X86Assembler::subss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700352 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
353 EmitUint8(0xF3);
354 EmitUint8(0x0F);
355 EmitUint8(0x5C);
356 EmitXmmRegisterOperand(dst, src);
357}
358
359
Ian Rogers2c8f6532011-09-02 17:16:34 -0700360void X86Assembler::subss(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700361 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
362 EmitUint8(0xF3);
363 EmitUint8(0x0F);
364 EmitUint8(0x5C);
365 EmitOperand(dst, src);
366}
367
368
Ian Rogers2c8f6532011-09-02 17:16:34 -0700369void X86Assembler::mulss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700370 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
371 EmitUint8(0xF3);
372 EmitUint8(0x0F);
373 EmitUint8(0x59);
374 EmitXmmRegisterOperand(dst, src);
375}
376
377
Ian Rogers2c8f6532011-09-02 17:16:34 -0700378void X86Assembler::mulss(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700379 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
380 EmitUint8(0xF3);
381 EmitUint8(0x0F);
382 EmitUint8(0x59);
383 EmitOperand(dst, src);
384}
385
386
Ian Rogers2c8f6532011-09-02 17:16:34 -0700387void X86Assembler::divss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700388 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
389 EmitUint8(0xF3);
390 EmitUint8(0x0F);
391 EmitUint8(0x5E);
392 EmitXmmRegisterOperand(dst, src);
393}
394
395
Ian Rogers2c8f6532011-09-02 17:16:34 -0700396void X86Assembler::divss(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700397 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
398 EmitUint8(0xF3);
399 EmitUint8(0x0F);
400 EmitUint8(0x5E);
401 EmitOperand(dst, src);
402}
403
404
Ian Rogers2c8f6532011-09-02 17:16:34 -0700405void X86Assembler::flds(const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700406 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
407 EmitUint8(0xD9);
408 EmitOperand(0, src);
409}
410
411
Ian Rogers2c8f6532011-09-02 17:16:34 -0700412void X86Assembler::fstps(const Address& dst) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700413 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
414 EmitUint8(0xD9);
415 EmitOperand(3, dst);
416}
417
418
Ian Rogers2c8f6532011-09-02 17:16:34 -0700419void X86Assembler::movsd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700420 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
421 EmitUint8(0xF2);
422 EmitUint8(0x0F);
423 EmitUint8(0x10);
424 EmitOperand(dst, src);
425}
426
427
Ian Rogers2c8f6532011-09-02 17:16:34 -0700428void X86Assembler::movsd(const Address& dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700429 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
430 EmitUint8(0xF2);
431 EmitUint8(0x0F);
432 EmitUint8(0x11);
433 EmitOperand(src, dst);
434}
435
436
Ian Rogers2c8f6532011-09-02 17:16:34 -0700437void X86Assembler::movsd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700438 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
439 EmitUint8(0xF2);
440 EmitUint8(0x0F);
441 EmitUint8(0x11);
442 EmitXmmRegisterOperand(src, dst);
443}
444
445
Ian Rogers2c8f6532011-09-02 17:16:34 -0700446void X86Assembler::addsd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700447 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
448 EmitUint8(0xF2);
449 EmitUint8(0x0F);
450 EmitUint8(0x58);
451 EmitXmmRegisterOperand(dst, src);
452}
453
454
Ian Rogers2c8f6532011-09-02 17:16:34 -0700455void X86Assembler::addsd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700456 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
457 EmitUint8(0xF2);
458 EmitUint8(0x0F);
459 EmitUint8(0x58);
460 EmitOperand(dst, src);
461}
462
463
Ian Rogers2c8f6532011-09-02 17:16:34 -0700464void X86Assembler::subsd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700465 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
466 EmitUint8(0xF2);
467 EmitUint8(0x0F);
468 EmitUint8(0x5C);
469 EmitXmmRegisterOperand(dst, src);
470}
471
472
Ian Rogers2c8f6532011-09-02 17:16:34 -0700473void X86Assembler::subsd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700474 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
475 EmitUint8(0xF2);
476 EmitUint8(0x0F);
477 EmitUint8(0x5C);
478 EmitOperand(dst, src);
479}
480
481
Ian Rogers2c8f6532011-09-02 17:16:34 -0700482void X86Assembler::mulsd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700483 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
484 EmitUint8(0xF2);
485 EmitUint8(0x0F);
486 EmitUint8(0x59);
487 EmitXmmRegisterOperand(dst, src);
488}
489
490
Ian Rogers2c8f6532011-09-02 17:16:34 -0700491void X86Assembler::mulsd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700492 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
493 EmitUint8(0xF2);
494 EmitUint8(0x0F);
495 EmitUint8(0x59);
496 EmitOperand(dst, src);
497}
498
499
Ian Rogers2c8f6532011-09-02 17:16:34 -0700500void X86Assembler::divsd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700501 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
502 EmitUint8(0xF2);
503 EmitUint8(0x0F);
504 EmitUint8(0x5E);
505 EmitXmmRegisterOperand(dst, src);
506}
507
508
Ian Rogers2c8f6532011-09-02 17:16:34 -0700509void X86Assembler::divsd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700510 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
511 EmitUint8(0xF2);
512 EmitUint8(0x0F);
513 EmitUint8(0x5E);
514 EmitOperand(dst, src);
515}
516
517
Ian Rogers2c8f6532011-09-02 17:16:34 -0700518void X86Assembler::cvtsi2ss(XmmRegister dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700519 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
520 EmitUint8(0xF3);
521 EmitUint8(0x0F);
522 EmitUint8(0x2A);
523 EmitOperand(dst, Operand(src));
524}
525
526
Ian Rogers2c8f6532011-09-02 17:16:34 -0700527void X86Assembler::cvtsi2sd(XmmRegister dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700528 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
529 EmitUint8(0xF2);
530 EmitUint8(0x0F);
531 EmitUint8(0x2A);
532 EmitOperand(dst, Operand(src));
533}
534
535
Ian Rogers2c8f6532011-09-02 17:16:34 -0700536void X86Assembler::cvtss2si(Register dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700537 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
538 EmitUint8(0xF3);
539 EmitUint8(0x0F);
540 EmitUint8(0x2D);
541 EmitXmmRegisterOperand(dst, src);
542}
543
544
Ian Rogers2c8f6532011-09-02 17:16:34 -0700545void X86Assembler::cvtss2sd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700546 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
547 EmitUint8(0xF3);
548 EmitUint8(0x0F);
549 EmitUint8(0x5A);
550 EmitXmmRegisterOperand(dst, src);
551}
552
553
Ian Rogers2c8f6532011-09-02 17:16:34 -0700554void X86Assembler::cvtsd2si(Register dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700555 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
556 EmitUint8(0xF2);
557 EmitUint8(0x0F);
558 EmitUint8(0x2D);
559 EmitXmmRegisterOperand(dst, src);
560}
561
562
Ian Rogers2c8f6532011-09-02 17:16:34 -0700563void X86Assembler::cvttss2si(Register dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700564 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
565 EmitUint8(0xF3);
566 EmitUint8(0x0F);
567 EmitUint8(0x2C);
568 EmitXmmRegisterOperand(dst, src);
569}
570
571
Ian Rogers2c8f6532011-09-02 17:16:34 -0700572void X86Assembler::cvttsd2si(Register dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700573 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
574 EmitUint8(0xF2);
575 EmitUint8(0x0F);
576 EmitUint8(0x2C);
577 EmitXmmRegisterOperand(dst, src);
578}
579
580
Ian Rogers2c8f6532011-09-02 17:16:34 -0700581void X86Assembler::cvtsd2ss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700582 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
583 EmitUint8(0xF2);
584 EmitUint8(0x0F);
585 EmitUint8(0x5A);
586 EmitXmmRegisterOperand(dst, src);
587}
588
589
Ian Rogers2c8f6532011-09-02 17:16:34 -0700590void X86Assembler::cvtdq2pd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700591 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
592 EmitUint8(0xF3);
593 EmitUint8(0x0F);
594 EmitUint8(0xE6);
595 EmitXmmRegisterOperand(dst, src);
596}
597
598
Ian Rogers2c8f6532011-09-02 17:16:34 -0700599void X86Assembler::comiss(XmmRegister a, XmmRegister b) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700600 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
601 EmitUint8(0x0F);
602 EmitUint8(0x2F);
603 EmitXmmRegisterOperand(a, b);
604}
605
606
Ian Rogers2c8f6532011-09-02 17:16:34 -0700607void X86Assembler::comisd(XmmRegister a, XmmRegister b) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700608 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
609 EmitUint8(0x66);
610 EmitUint8(0x0F);
611 EmitUint8(0x2F);
612 EmitXmmRegisterOperand(a, b);
613}
614
615
Ian Rogers2c8f6532011-09-02 17:16:34 -0700616void X86Assembler::sqrtsd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700617 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
618 EmitUint8(0xF2);
619 EmitUint8(0x0F);
620 EmitUint8(0x51);
621 EmitXmmRegisterOperand(dst, src);
622}
623
624
Ian Rogers2c8f6532011-09-02 17:16:34 -0700625void X86Assembler::sqrtss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700626 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
627 EmitUint8(0xF3);
628 EmitUint8(0x0F);
629 EmitUint8(0x51);
630 EmitXmmRegisterOperand(dst, src);
631}
632
633
Ian Rogers2c8f6532011-09-02 17:16:34 -0700634void X86Assembler::xorpd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700635 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
636 EmitUint8(0x66);
637 EmitUint8(0x0F);
638 EmitUint8(0x57);
639 EmitOperand(dst, src);
640}
641
642
Ian Rogers2c8f6532011-09-02 17:16:34 -0700643void X86Assembler::xorpd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700644 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
645 EmitUint8(0x66);
646 EmitUint8(0x0F);
647 EmitUint8(0x57);
648 EmitXmmRegisterOperand(dst, src);
649}
650
651
Ian Rogers2c8f6532011-09-02 17:16:34 -0700652void X86Assembler::xorps(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700653 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
654 EmitUint8(0x0F);
655 EmitUint8(0x57);
656 EmitOperand(dst, src);
657}
658
659
Ian Rogers2c8f6532011-09-02 17:16:34 -0700660void X86Assembler::xorps(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700661 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
662 EmitUint8(0x0F);
663 EmitUint8(0x57);
664 EmitXmmRegisterOperand(dst, src);
665}
666
667
Ian Rogers2c8f6532011-09-02 17:16:34 -0700668void X86Assembler::andpd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700669 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
670 EmitUint8(0x66);
671 EmitUint8(0x0F);
672 EmitUint8(0x54);
673 EmitOperand(dst, src);
674}
675
676
Ian Rogers2c8f6532011-09-02 17:16:34 -0700677void X86Assembler::fldl(const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700678 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
679 EmitUint8(0xDD);
680 EmitOperand(0, src);
681}
682
683
Ian Rogers2c8f6532011-09-02 17:16:34 -0700684void X86Assembler::fstpl(const Address& dst) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700685 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
686 EmitUint8(0xDD);
687 EmitOperand(3, dst);
688}
689
690
Ian Rogers2c8f6532011-09-02 17:16:34 -0700691void X86Assembler::fnstcw(const Address& dst) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700692 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
693 EmitUint8(0xD9);
694 EmitOperand(7, dst);
695}
696
697
Ian Rogers2c8f6532011-09-02 17:16:34 -0700698void X86Assembler::fldcw(const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700699 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
700 EmitUint8(0xD9);
701 EmitOperand(5, src);
702}
703
704
Ian Rogers2c8f6532011-09-02 17:16:34 -0700705void X86Assembler::fistpl(const Address& dst) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700706 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
707 EmitUint8(0xDF);
708 EmitOperand(7, dst);
709}
710
711
Ian Rogers2c8f6532011-09-02 17:16:34 -0700712void X86Assembler::fistps(const Address& dst) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700713 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
714 EmitUint8(0xDB);
715 EmitOperand(3, dst);
716}
717
718
Ian Rogers2c8f6532011-09-02 17:16:34 -0700719void X86Assembler::fildl(const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700720 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
721 EmitUint8(0xDF);
722 EmitOperand(5, src);
723}
724
725
Ian Rogers2c8f6532011-09-02 17:16:34 -0700726void X86Assembler::fincstp() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700727 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
728 EmitUint8(0xD9);
729 EmitUint8(0xF7);
730}
731
732
Ian Rogers2c8f6532011-09-02 17:16:34 -0700733void X86Assembler::ffree(const Immediate& index) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700734 CHECK_LT(index.value(), 7);
735 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
736 EmitUint8(0xDD);
737 EmitUint8(0xC0 + index.value());
738}
739
740
Ian Rogers2c8f6532011-09-02 17:16:34 -0700741void X86Assembler::fsin() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700742 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
743 EmitUint8(0xD9);
744 EmitUint8(0xFE);
745}
746
747
Ian Rogers2c8f6532011-09-02 17:16:34 -0700748void X86Assembler::fcos() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700749 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
750 EmitUint8(0xD9);
751 EmitUint8(0xFF);
752}
753
754
Ian Rogers2c8f6532011-09-02 17:16:34 -0700755void X86Assembler::fptan() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700756 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
757 EmitUint8(0xD9);
758 EmitUint8(0xF2);
759}
760
761
Ian Rogers2c8f6532011-09-02 17:16:34 -0700762void X86Assembler::xchgl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700763 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
764 EmitUint8(0x87);
765 EmitRegisterOperand(dst, src);
766}
767
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100768
Ian Rogers7caad772012-03-30 01:07:54 -0700769void X86Assembler::xchgl(Register reg, const Address& address) {
770 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
771 EmitUint8(0x87);
772 EmitOperand(reg, address);
773}
774
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700775
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100776void X86Assembler::cmpw(const Address& address, const Immediate& imm) {
777 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
778 EmitUint8(0x66);
779 EmitComplex(7, address, imm);
780}
781
782
Ian Rogers2c8f6532011-09-02 17:16:34 -0700783void X86Assembler::cmpl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700784 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
785 EmitComplex(7, Operand(reg), imm);
786}
787
788
Ian Rogers2c8f6532011-09-02 17:16:34 -0700789void X86Assembler::cmpl(Register reg0, Register reg1) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700790 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
791 EmitUint8(0x3B);
792 EmitOperand(reg0, Operand(reg1));
793}
794
795
Ian Rogers2c8f6532011-09-02 17:16:34 -0700796void X86Assembler::cmpl(Register reg, const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700797 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
798 EmitUint8(0x3B);
799 EmitOperand(reg, address);
800}
801
802
Ian Rogers2c8f6532011-09-02 17:16:34 -0700803void X86Assembler::addl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700804 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
805 EmitUint8(0x03);
806 EmitRegisterOperand(dst, src);
807}
808
809
Ian Rogers2c8f6532011-09-02 17:16:34 -0700810void X86Assembler::addl(Register reg, const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700811 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
812 EmitUint8(0x03);
813 EmitOperand(reg, address);
814}
815
816
Ian Rogers2c8f6532011-09-02 17:16:34 -0700817void X86Assembler::cmpl(const Address& address, Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700818 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
819 EmitUint8(0x39);
820 EmitOperand(reg, address);
821}
822
823
Ian Rogers2c8f6532011-09-02 17:16:34 -0700824void X86Assembler::cmpl(const Address& address, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700825 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
826 EmitComplex(7, address, imm);
827}
828
829
Ian Rogers2c8f6532011-09-02 17:16:34 -0700830void X86Assembler::testl(Register reg1, Register reg2) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700831 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
832 EmitUint8(0x85);
833 EmitRegisterOperand(reg1, reg2);
834}
835
836
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100837void X86Assembler::testl(Register reg, const Address& address) {
838 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
839 EmitUint8(0x85);
840 EmitOperand(reg, address);
841}
842
843
Ian Rogers2c8f6532011-09-02 17:16:34 -0700844void X86Assembler::testl(Register reg, const Immediate& immediate) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700845 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
846 // For registers that have a byte variant (EAX, EBX, ECX, and EDX)
847 // we only test the byte register to keep the encoding short.
848 if (immediate.is_uint8() && reg < 4) {
849 // Use zero-extended 8-bit immediate.
850 if (reg == EAX) {
851 EmitUint8(0xA8);
852 } else {
853 EmitUint8(0xF6);
854 EmitUint8(0xC0 + reg);
855 }
856 EmitUint8(immediate.value() & 0xFF);
857 } else if (reg == EAX) {
858 // Use short form if the destination is EAX.
859 EmitUint8(0xA9);
860 EmitImmediate(immediate);
861 } else {
862 EmitUint8(0xF7);
863 EmitOperand(0, Operand(reg));
864 EmitImmediate(immediate);
865 }
866}
867
868
Ian Rogers2c8f6532011-09-02 17:16:34 -0700869void X86Assembler::andl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700870 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
871 EmitUint8(0x23);
872 EmitOperand(dst, Operand(src));
873}
874
875
Ian Rogers2c8f6532011-09-02 17:16:34 -0700876void X86Assembler::andl(Register dst, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700877 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
878 EmitComplex(4, Operand(dst), imm);
879}
880
881
Ian Rogers2c8f6532011-09-02 17:16:34 -0700882void X86Assembler::orl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700883 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
884 EmitUint8(0x0B);
885 EmitOperand(dst, Operand(src));
886}
887
888
Ian Rogers2c8f6532011-09-02 17:16:34 -0700889void X86Assembler::orl(Register dst, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700890 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
891 EmitComplex(1, Operand(dst), imm);
892}
893
894
Ian Rogers2c8f6532011-09-02 17:16:34 -0700895void X86Assembler::xorl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700896 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
897 EmitUint8(0x33);
898 EmitOperand(dst, Operand(src));
899}
900
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100901void X86Assembler::xorl(Register dst, const Immediate& imm) {
902 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
903 EmitComplex(6, Operand(dst), imm);
904}
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700905
Ian Rogers2c8f6532011-09-02 17:16:34 -0700906void X86Assembler::addl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700907 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
908 EmitComplex(0, Operand(reg), imm);
909}
910
911
Ian Rogers2c8f6532011-09-02 17:16:34 -0700912void X86Assembler::addl(const Address& address, Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700913 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
914 EmitUint8(0x01);
915 EmitOperand(reg, address);
916}
917
918
Ian Rogers2c8f6532011-09-02 17:16:34 -0700919void X86Assembler::addl(const Address& address, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700920 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
921 EmitComplex(0, address, imm);
922}
923
924
Ian Rogers2c8f6532011-09-02 17:16:34 -0700925void X86Assembler::adcl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700926 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
927 EmitComplex(2, Operand(reg), imm);
928}
929
930
Ian Rogers2c8f6532011-09-02 17:16:34 -0700931void X86Assembler::adcl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700932 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
933 EmitUint8(0x13);
934 EmitOperand(dst, Operand(src));
935}
936
937
Ian Rogers2c8f6532011-09-02 17:16:34 -0700938void X86Assembler::adcl(Register dst, const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700939 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
940 EmitUint8(0x13);
941 EmitOperand(dst, address);
942}
943
944
Ian Rogers2c8f6532011-09-02 17:16:34 -0700945void X86Assembler::subl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700946 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
947 EmitUint8(0x2B);
948 EmitOperand(dst, Operand(src));
949}
950
951
Ian Rogers2c8f6532011-09-02 17:16:34 -0700952void X86Assembler::subl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700953 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
954 EmitComplex(5, Operand(reg), imm);
955}
956
957
Ian Rogers2c8f6532011-09-02 17:16:34 -0700958void X86Assembler::subl(Register reg, const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700959 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
960 EmitUint8(0x2B);
961 EmitOperand(reg, address);
962}
963
964
Ian Rogers2c8f6532011-09-02 17:16:34 -0700965void X86Assembler::cdq() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700966 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
967 EmitUint8(0x99);
968}
969
970
Ian Rogers2c8f6532011-09-02 17:16:34 -0700971void X86Assembler::idivl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700972 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
973 EmitUint8(0xF7);
974 EmitUint8(0xF8 | reg);
975}
976
977
Ian Rogers2c8f6532011-09-02 17:16:34 -0700978void X86Assembler::imull(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700979 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
980 EmitUint8(0x0F);
981 EmitUint8(0xAF);
982 EmitOperand(dst, Operand(src));
983}
984
985
Ian Rogers2c8f6532011-09-02 17:16:34 -0700986void X86Assembler::imull(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700987 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
988 EmitUint8(0x69);
989 EmitOperand(reg, Operand(reg));
990 EmitImmediate(imm);
991}
992
993
Ian Rogers2c8f6532011-09-02 17:16:34 -0700994void X86Assembler::imull(Register reg, const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700995 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
996 EmitUint8(0x0F);
997 EmitUint8(0xAF);
998 EmitOperand(reg, address);
999}
1000
1001
Ian Rogers2c8f6532011-09-02 17:16:34 -07001002void X86Assembler::imull(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001003 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1004 EmitUint8(0xF7);
1005 EmitOperand(5, Operand(reg));
1006}
1007
1008
Ian Rogers2c8f6532011-09-02 17:16:34 -07001009void X86Assembler::imull(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001010 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1011 EmitUint8(0xF7);
1012 EmitOperand(5, address);
1013}
1014
1015
Ian Rogers2c8f6532011-09-02 17:16:34 -07001016void X86Assembler::mull(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001017 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1018 EmitUint8(0xF7);
1019 EmitOperand(4, Operand(reg));
1020}
1021
1022
Ian Rogers2c8f6532011-09-02 17:16:34 -07001023void X86Assembler::mull(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001024 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1025 EmitUint8(0xF7);
1026 EmitOperand(4, address);
1027}
1028
1029
Ian Rogers2c8f6532011-09-02 17:16:34 -07001030void X86Assembler::sbbl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001031 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1032 EmitUint8(0x1B);
1033 EmitOperand(dst, Operand(src));
1034}
1035
1036
Ian Rogers2c8f6532011-09-02 17:16:34 -07001037void X86Assembler::sbbl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001038 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1039 EmitComplex(3, Operand(reg), imm);
1040}
1041
1042
Ian Rogers2c8f6532011-09-02 17:16:34 -07001043void X86Assembler::sbbl(Register dst, const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001044 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1045 EmitUint8(0x1B);
1046 EmitOperand(dst, address);
1047}
1048
1049
Ian Rogers2c8f6532011-09-02 17:16:34 -07001050void X86Assembler::incl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001051 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1052 EmitUint8(0x40 + reg);
1053}
1054
1055
Ian Rogers2c8f6532011-09-02 17:16:34 -07001056void X86Assembler::incl(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001057 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1058 EmitUint8(0xFF);
1059 EmitOperand(0, address);
1060}
1061
1062
Ian Rogers2c8f6532011-09-02 17:16:34 -07001063void X86Assembler::decl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001064 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1065 EmitUint8(0x48 + reg);
1066}
1067
1068
Ian Rogers2c8f6532011-09-02 17:16:34 -07001069void X86Assembler::decl(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001070 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1071 EmitUint8(0xFF);
1072 EmitOperand(1, address);
1073}
1074
1075
Ian Rogers2c8f6532011-09-02 17:16:34 -07001076void X86Assembler::shll(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001077 EmitGenericShift(4, reg, imm);
1078}
1079
1080
Ian Rogers2c8f6532011-09-02 17:16:34 -07001081void X86Assembler::shll(Register operand, Register shifter) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001082 EmitGenericShift(4, operand, shifter);
1083}
1084
1085
Ian Rogers2c8f6532011-09-02 17:16:34 -07001086void X86Assembler::shrl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001087 EmitGenericShift(5, reg, imm);
1088}
1089
1090
Ian Rogers2c8f6532011-09-02 17:16:34 -07001091void X86Assembler::shrl(Register operand, Register shifter) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001092 EmitGenericShift(5, operand, shifter);
1093}
1094
1095
Ian Rogers2c8f6532011-09-02 17:16:34 -07001096void X86Assembler::sarl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001097 EmitGenericShift(7, reg, imm);
1098}
1099
1100
Ian Rogers2c8f6532011-09-02 17:16:34 -07001101void X86Assembler::sarl(Register operand, Register shifter) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001102 EmitGenericShift(7, operand, shifter);
1103}
1104
1105
Ian Rogers2c8f6532011-09-02 17:16:34 -07001106void X86Assembler::shld(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001107 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1108 EmitUint8(0x0F);
1109 EmitUint8(0xA5);
1110 EmitRegisterOperand(src, dst);
1111}
1112
1113
Ian Rogers2c8f6532011-09-02 17:16:34 -07001114void X86Assembler::negl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001115 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1116 EmitUint8(0xF7);
1117 EmitOperand(3, Operand(reg));
1118}
1119
1120
Ian Rogers2c8f6532011-09-02 17:16:34 -07001121void X86Assembler::notl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001122 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1123 EmitUint8(0xF7);
1124 EmitUint8(0xD0 | reg);
1125}
1126
1127
Ian Rogers2c8f6532011-09-02 17:16:34 -07001128void X86Assembler::enter(const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001129 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1130 EmitUint8(0xC8);
1131 CHECK(imm.is_uint16());
1132 EmitUint8(imm.value() & 0xFF);
1133 EmitUint8((imm.value() >> 8) & 0xFF);
1134 EmitUint8(0x00);
1135}
1136
1137
Ian Rogers2c8f6532011-09-02 17:16:34 -07001138void X86Assembler::leave() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001139 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1140 EmitUint8(0xC9);
1141}
1142
1143
Ian Rogers2c8f6532011-09-02 17:16:34 -07001144void X86Assembler::ret() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001145 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1146 EmitUint8(0xC3);
1147}
1148
1149
Ian Rogers2c8f6532011-09-02 17:16:34 -07001150void X86Assembler::ret(const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001151 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1152 EmitUint8(0xC2);
1153 CHECK(imm.is_uint16());
1154 EmitUint8(imm.value() & 0xFF);
1155 EmitUint8((imm.value() >> 8) & 0xFF);
1156}
1157
1158
1159
Ian Rogers2c8f6532011-09-02 17:16:34 -07001160void X86Assembler::nop() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001161 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1162 EmitUint8(0x90);
1163}
1164
1165
Ian Rogers2c8f6532011-09-02 17:16:34 -07001166void X86Assembler::int3() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001167 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1168 EmitUint8(0xCC);
1169}
1170
1171
Ian Rogers2c8f6532011-09-02 17:16:34 -07001172void X86Assembler::hlt() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001173 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1174 EmitUint8(0xF4);
1175}
1176
1177
Ian Rogers2c8f6532011-09-02 17:16:34 -07001178void X86Assembler::j(Condition condition, Label* label) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001179 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1180 if (label->IsBound()) {
1181 static const int kShortSize = 2;
1182 static const int kLongSize = 6;
1183 int offset = label->Position() - buffer_.Size();
1184 CHECK_LE(offset, 0);
1185 if (IsInt(8, offset - kShortSize)) {
1186 EmitUint8(0x70 + condition);
1187 EmitUint8((offset - kShortSize) & 0xFF);
1188 } else {
1189 EmitUint8(0x0F);
1190 EmitUint8(0x80 + condition);
1191 EmitInt32(offset - kLongSize);
1192 }
1193 } else {
1194 EmitUint8(0x0F);
1195 EmitUint8(0x80 + condition);
1196 EmitLabelLink(label);
1197 }
1198}
1199
1200
Ian Rogers2c8f6532011-09-02 17:16:34 -07001201void X86Assembler::jmp(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001202 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1203 EmitUint8(0xFF);
1204 EmitRegisterOperand(4, reg);
1205}
1206
Ian Rogers7caad772012-03-30 01:07:54 -07001207void X86Assembler::jmp(const Address& address) {
1208 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1209 EmitUint8(0xFF);
1210 EmitOperand(4, address);
1211}
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001212
Ian Rogers2c8f6532011-09-02 17:16:34 -07001213void X86Assembler::jmp(Label* label) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001214 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1215 if (label->IsBound()) {
1216 static const int kShortSize = 2;
1217 static const int kLongSize = 5;
1218 int offset = label->Position() - buffer_.Size();
1219 CHECK_LE(offset, 0);
1220 if (IsInt(8, offset - kShortSize)) {
1221 EmitUint8(0xEB);
1222 EmitUint8((offset - kShortSize) & 0xFF);
1223 } else {
1224 EmitUint8(0xE9);
1225 EmitInt32(offset - kLongSize);
1226 }
1227 } else {
1228 EmitUint8(0xE9);
1229 EmitLabelLink(label);
1230 }
1231}
1232
1233
Ian Rogers2c8f6532011-09-02 17:16:34 -07001234X86Assembler* X86Assembler::lock() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001235 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1236 EmitUint8(0xF0);
Ian Rogers0d666d82011-08-14 16:03:46 -07001237 return this;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001238}
1239
1240
Ian Rogers2c8f6532011-09-02 17:16:34 -07001241void X86Assembler::cmpxchgl(const Address& address, Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001242 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1243 EmitUint8(0x0F);
1244 EmitUint8(0xB1);
1245 EmitOperand(reg, address);
1246}
1247
Elliott Hughes79ab9e32012-03-12 15:41:35 -07001248void X86Assembler::mfence() {
1249 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1250 EmitUint8(0x0F);
1251 EmitUint8(0xAE);
1252 EmitUint8(0xF0);
1253}
1254
Ian Rogers2c8f6532011-09-02 17:16:34 -07001255X86Assembler* X86Assembler::fs() {
Ian Rogersb033c752011-07-20 12:22:35 -07001256 // TODO: fs is a prefix and not an instruction
1257 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1258 EmitUint8(0x64);
Ian Rogers0d666d82011-08-14 16:03:46 -07001259 return this;
Ian Rogersb033c752011-07-20 12:22:35 -07001260}
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001261
Ian Rogersbefbd572014-03-06 01:13:39 -08001262X86Assembler* X86Assembler::gs() {
1263 // TODO: fs is a prefix and not an instruction
1264 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1265 EmitUint8(0x65);
1266 return this;
1267}
1268
Ian Rogers2c8f6532011-09-02 17:16:34 -07001269void X86Assembler::AddImmediate(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001270 int value = imm.value();
1271 if (value > 0) {
1272 if (value == 1) {
1273 incl(reg);
1274 } else if (value != 0) {
1275 addl(reg, imm);
1276 }
1277 } else if (value < 0) {
1278 value = -value;
1279 if (value == 1) {
1280 decl(reg);
1281 } else if (value != 0) {
1282 subl(reg, Immediate(value));
1283 }
1284 }
1285}
1286
1287
Ian Rogers2c8f6532011-09-02 17:16:34 -07001288void X86Assembler::LoadDoubleConstant(XmmRegister dst, double value) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001289 // TODO: Need to have a code constants table.
1290 int64_t constant = bit_cast<int64_t, double>(value);
1291 pushl(Immediate(High32Bits(constant)));
1292 pushl(Immediate(Low32Bits(constant)));
1293 movsd(dst, Address(ESP, 0));
1294 addl(ESP, Immediate(2 * kWordSize));
1295}
1296
1297
Ian Rogers2c8f6532011-09-02 17:16:34 -07001298void X86Assembler::FloatNegate(XmmRegister f) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001299 static const struct {
1300 uint32_t a;
1301 uint32_t b;
1302 uint32_t c;
1303 uint32_t d;
1304 } float_negate_constant __attribute__((aligned(16))) =
1305 { 0x80000000, 0x00000000, 0x80000000, 0x00000000 };
1306 xorps(f, Address::Absolute(reinterpret_cast<uword>(&float_negate_constant)));
1307}
1308
1309
Ian Rogers2c8f6532011-09-02 17:16:34 -07001310void X86Assembler::DoubleNegate(XmmRegister d) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001311 static const struct {
1312 uint64_t a;
1313 uint64_t b;
1314 } double_negate_constant __attribute__((aligned(16))) =
1315 {0x8000000000000000LL, 0x8000000000000000LL};
1316 xorpd(d, Address::Absolute(reinterpret_cast<uword>(&double_negate_constant)));
1317}
1318
1319
Ian Rogers2c8f6532011-09-02 17:16:34 -07001320void X86Assembler::DoubleAbs(XmmRegister reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001321 static const struct {
1322 uint64_t a;
1323 uint64_t b;
1324 } double_abs_constant __attribute__((aligned(16))) =
1325 {0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFFLL};
1326 andpd(reg, Address::Absolute(reinterpret_cast<uword>(&double_abs_constant)));
1327}
1328
1329
Ian Rogers2c8f6532011-09-02 17:16:34 -07001330void X86Assembler::Align(int alignment, int offset) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001331 CHECK(IsPowerOfTwo(alignment));
1332 // Emit nop instruction until the real position is aligned.
1333 while (((offset + buffer_.GetPosition()) & (alignment-1)) != 0) {
1334 nop();
1335 }
1336}
1337
1338
Ian Rogers2c8f6532011-09-02 17:16:34 -07001339void X86Assembler::Bind(Label* label) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001340 int bound = buffer_.Size();
1341 CHECK(!label->IsBound()); // Labels can only be bound once.
1342 while (label->IsLinked()) {
1343 int position = label->LinkPosition();
1344 int next = buffer_.Load<int32_t>(position);
1345 buffer_.Store<int32_t>(position, bound - (position + 4));
1346 label->position_ = next;
1347 }
1348 label->BindTo(bound);
1349}
1350
1351
Ian Rogers44fb0d02012-03-23 16:46:24 -07001352void X86Assembler::EmitOperand(int reg_or_opcode, const Operand& operand) {
1353 CHECK_GE(reg_or_opcode, 0);
1354 CHECK_LT(reg_or_opcode, 8);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001355 const int length = operand.length_;
1356 CHECK_GT(length, 0);
Ian Rogers44fb0d02012-03-23 16:46:24 -07001357 // Emit the ModRM byte updated with the given reg value.
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001358 CHECK_EQ(operand.encoding_[0] & 0x38, 0);
Ian Rogers44fb0d02012-03-23 16:46:24 -07001359 EmitUint8(operand.encoding_[0] + (reg_or_opcode << 3));
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001360 // Emit the rest of the encoded operand.
1361 for (int i = 1; i < length; i++) {
1362 EmitUint8(operand.encoding_[i]);
1363 }
1364}
1365
1366
Ian Rogers2c8f6532011-09-02 17:16:34 -07001367void X86Assembler::EmitImmediate(const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001368 EmitInt32(imm.value());
1369}
1370
1371
Ian Rogers44fb0d02012-03-23 16:46:24 -07001372void X86Assembler::EmitComplex(int reg_or_opcode,
Ian Rogers2c8f6532011-09-02 17:16:34 -07001373 const Operand& operand,
1374 const Immediate& immediate) {
Ian Rogers44fb0d02012-03-23 16:46:24 -07001375 CHECK_GE(reg_or_opcode, 0);
1376 CHECK_LT(reg_or_opcode, 8);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001377 if (immediate.is_int8()) {
1378 // Use sign-extended 8-bit immediate.
1379 EmitUint8(0x83);
Ian Rogers44fb0d02012-03-23 16:46:24 -07001380 EmitOperand(reg_or_opcode, operand);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001381 EmitUint8(immediate.value() & 0xFF);
1382 } else if (operand.IsRegister(EAX)) {
1383 // Use short form if the destination is eax.
Ian Rogers44fb0d02012-03-23 16:46:24 -07001384 EmitUint8(0x05 + (reg_or_opcode << 3));
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001385 EmitImmediate(immediate);
1386 } else {
1387 EmitUint8(0x81);
Ian Rogers44fb0d02012-03-23 16:46:24 -07001388 EmitOperand(reg_or_opcode, operand);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001389 EmitImmediate(immediate);
1390 }
1391}
1392
1393
Ian Rogers2c8f6532011-09-02 17:16:34 -07001394void X86Assembler::EmitLabel(Label* label, int instruction_size) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001395 if (label->IsBound()) {
1396 int offset = label->Position() - buffer_.Size();
1397 CHECK_LE(offset, 0);
1398 EmitInt32(offset - instruction_size);
1399 } else {
1400 EmitLabelLink(label);
1401 }
1402}
1403
1404
Ian Rogers2c8f6532011-09-02 17:16:34 -07001405void X86Assembler::EmitLabelLink(Label* label) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001406 CHECK(!label->IsBound());
1407 int position = buffer_.Size();
1408 EmitInt32(label->position_);
1409 label->LinkTo(position);
1410}
1411
1412
Ian Rogers44fb0d02012-03-23 16:46:24 -07001413void X86Assembler::EmitGenericShift(int reg_or_opcode,
Ian Rogers2c8f6532011-09-02 17:16:34 -07001414 Register reg,
1415 const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001416 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1417 CHECK(imm.is_int8());
1418 if (imm.value() == 1) {
1419 EmitUint8(0xD1);
Ian Rogers44fb0d02012-03-23 16:46:24 -07001420 EmitOperand(reg_or_opcode, Operand(reg));
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001421 } else {
1422 EmitUint8(0xC1);
Ian Rogers44fb0d02012-03-23 16:46:24 -07001423 EmitOperand(reg_or_opcode, Operand(reg));
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001424 EmitUint8(imm.value() & 0xFF);
1425 }
1426}
1427
1428
Ian Rogers44fb0d02012-03-23 16:46:24 -07001429void X86Assembler::EmitGenericShift(int reg_or_opcode,
Ian Rogers2c8f6532011-09-02 17:16:34 -07001430 Register operand,
1431 Register shifter) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001432 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1433 CHECK_EQ(shifter, ECX);
1434 EmitUint8(0xD3);
Ian Rogers44fb0d02012-03-23 16:46:24 -07001435 EmitOperand(reg_or_opcode, Operand(operand));
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001436}
1437
Tong Shen547cdfd2014-08-05 01:54:19 -07001438void X86Assembler::InitializeFrameDescriptionEntry() {
Yevgeny Roubane3ea8382014-08-08 16:29:38 +07001439 WriteFDEHeader(&cfi_info_, false /* is_64bit */);
Tong Shen547cdfd2014-08-05 01:54:19 -07001440}
1441
1442void X86Assembler::FinalizeFrameDescriptionEntry() {
Yevgeny Roubane3ea8382014-08-08 16:29:38 +07001443 WriteFDEAddressRange(&cfi_info_, buffer_.Size(), false /* is_64bit */);
Tong Shen547cdfd2014-08-05 01:54:19 -07001444 PadCFI(&cfi_info_);
Yevgeny Roubane3ea8382014-08-08 16:29:38 +07001445 WriteCFILength(&cfi_info_, false /* is_64bit */);
Tong Shen547cdfd2014-08-05 01:54:19 -07001446}
1447
Ian Rogers790a6b72014-04-01 10:36:00 -07001448constexpr size_t kFramePointerSize = 4;
1449
Ian Rogers2c8f6532011-09-02 17:16:34 -07001450void X86Assembler::BuildFrame(size_t frame_size, ManagedRegister method_reg,
Ian Rogersb5d09b22012-03-06 22:14:17 -08001451 const std::vector<ManagedRegister>& spill_regs,
Dmitry Petrochenkofca82202014-03-21 11:21:37 +07001452 const ManagedRegisterEntrySpills& entry_spills) {
Tong Shen547cdfd2014-08-05 01:54:19 -07001453 cfi_cfa_offset_ = kFramePointerSize; // Only return address on stack
1454 cfi_pc_ = buffer_.Size(); // Nothing emitted yet
1455 DCHECK_EQ(cfi_pc_, 0U);
1456
1457 uint32_t reg_offset = 1;
Elliott Hughes06b37d92011-10-16 11:51:29 -07001458 CHECK_ALIGNED(frame_size, kStackAlignment);
jeffhao703f2cd2012-07-13 17:25:52 -07001459 for (int i = spill_regs.size() - 1; i >= 0; --i) {
1460 pushl(spill_regs.at(i).AsX86().AsCpuRegister());
Tong Shen547cdfd2014-08-05 01:54:19 -07001461
1462 // DW_CFA_advance_loc
1463 DW_CFA_advance_loc(&cfi_info_, buffer_.Size() - cfi_pc_);
1464 cfi_pc_ = buffer_.Size();
1465 // DW_CFA_def_cfa_offset
1466 cfi_cfa_offset_ += kFramePointerSize;
1467 DW_CFA_def_cfa_offset(&cfi_info_, cfi_cfa_offset_);
1468 // DW_CFA_offset reg offset
1469 reg_offset++;
1470 DW_CFA_offset(&cfi_info_, spill_regs.at(i).AsX86().DWARFRegId(), reg_offset);
jeffhao703f2cd2012-07-13 17:25:52 -07001471 }
Tong Shen547cdfd2014-08-05 01:54:19 -07001472
Ian Rogersb033c752011-07-20 12:22:35 -07001473 // return address then method on stack
Tong Shen547cdfd2014-08-05 01:54:19 -07001474 int32_t adjust = frame_size - (spill_regs.size() * kFramePointerSize) -
1475 sizeof(StackReference<mirror::ArtMethod>) /*method*/ -
1476 kFramePointerSize /*return address*/;
1477 addl(ESP, Immediate(-adjust));
1478 // DW_CFA_advance_loc
1479 DW_CFA_advance_loc(&cfi_info_, buffer_.Size() - cfi_pc_);
1480 cfi_pc_ = buffer_.Size();
1481 // DW_CFA_def_cfa_offset
1482 cfi_cfa_offset_ += adjust;
1483 DW_CFA_def_cfa_offset(&cfi_info_, cfi_cfa_offset_);
1484
Ian Rogers2c8f6532011-09-02 17:16:34 -07001485 pushl(method_reg.AsX86().AsCpuRegister());
Tong Shen547cdfd2014-08-05 01:54:19 -07001486 // DW_CFA_advance_loc
1487 DW_CFA_advance_loc(&cfi_info_, buffer_.Size() - cfi_pc_);
1488 cfi_pc_ = buffer_.Size();
1489 // DW_CFA_def_cfa_offset
1490 cfi_cfa_offset_ += kFramePointerSize;
1491 DW_CFA_def_cfa_offset(&cfi_info_, cfi_cfa_offset_);
1492
Ian Rogersb5d09b22012-03-06 22:14:17 -08001493 for (size_t i = 0; i < entry_spills.size(); ++i) {
Andreas Gampecf4035a2014-05-28 22:43:01 -07001494 movl(Address(ESP, frame_size + sizeof(StackReference<mirror::ArtMethod>) +
1495 (i * kFramePointerSize)),
Ian Rogersb5d09b22012-03-06 22:14:17 -08001496 entry_spills.at(i).AsX86().AsCpuRegister());
1497 }
Ian Rogersb033c752011-07-20 12:22:35 -07001498}
1499
Ian Rogers2c8f6532011-09-02 17:16:34 -07001500void X86Assembler::RemoveFrame(size_t frame_size,
Ian Rogers0d666d82011-08-14 16:03:46 -07001501 const std::vector<ManagedRegister>& spill_regs) {
Elliott Hughes06b37d92011-10-16 11:51:29 -07001502 CHECK_ALIGNED(frame_size, kStackAlignment);
Andreas Gampecf4035a2014-05-28 22:43:01 -07001503 addl(ESP, Immediate(frame_size - (spill_regs.size() * kFramePointerSize) -
1504 sizeof(StackReference<mirror::ArtMethod>)));
jeffhao703f2cd2012-07-13 17:25:52 -07001505 for (size_t i = 0; i < spill_regs.size(); ++i) {
1506 popl(spill_regs.at(i).AsX86().AsCpuRegister());
1507 }
Ian Rogersb033c752011-07-20 12:22:35 -07001508 ret();
1509}
1510
Ian Rogers2c8f6532011-09-02 17:16:34 -07001511void X86Assembler::IncreaseFrameSize(size_t adjust) {
Elliott Hughes06b37d92011-10-16 11:51:29 -07001512 CHECK_ALIGNED(adjust, kStackAlignment);
Ian Rogersb033c752011-07-20 12:22:35 -07001513 addl(ESP, Immediate(-adjust));
Tong Shen547cdfd2014-08-05 01:54:19 -07001514 // DW_CFA_advance_loc
1515 DW_CFA_advance_loc(&cfi_info_, buffer_.Size() - cfi_pc_);
1516 cfi_pc_ = buffer_.Size();
1517 // DW_CFA_def_cfa_offset
1518 cfi_cfa_offset_ += adjust;
1519 DW_CFA_def_cfa_offset(&cfi_info_, cfi_cfa_offset_);
Ian Rogersb033c752011-07-20 12:22:35 -07001520}
1521
Ian Rogers2c8f6532011-09-02 17:16:34 -07001522void X86Assembler::DecreaseFrameSize(size_t adjust) {
Elliott Hughes06b37d92011-10-16 11:51:29 -07001523 CHECK_ALIGNED(adjust, kStackAlignment);
Ian Rogersb033c752011-07-20 12:22:35 -07001524 addl(ESP, Immediate(adjust));
1525}
1526
Ian Rogers2c8f6532011-09-02 17:16:34 -07001527void X86Assembler::Store(FrameOffset offs, ManagedRegister msrc, size_t size) {
1528 X86ManagedRegister src = msrc.AsX86();
Ian Rogers45a76cb2011-07-21 22:00:15 -07001529 if (src.IsNoRegister()) {
1530 CHECK_EQ(0u, size);
1531 } else if (src.IsCpuRegister()) {
Ian Rogersb033c752011-07-20 12:22:35 -07001532 CHECK_EQ(4u, size);
1533 movl(Address(ESP, offs), src.AsCpuRegister());
Ian Rogers9b269d22011-09-04 14:06:05 -07001534 } else if (src.IsRegisterPair()) {
1535 CHECK_EQ(8u, size);
1536 movl(Address(ESP, offs), src.AsRegisterPairLow());
1537 movl(Address(ESP, FrameOffset(offs.Int32Value()+4)),
1538 src.AsRegisterPairHigh());
Ian Rogers45a76cb2011-07-21 22:00:15 -07001539 } else if (src.IsX87Register()) {
1540 if (size == 4) {
1541 fstps(Address(ESP, offs));
1542 } else {
1543 fstpl(Address(ESP, offs));
1544 }
1545 } else {
1546 CHECK(src.IsXmmRegister());
Ian Rogersb033c752011-07-20 12:22:35 -07001547 if (size == 4) {
1548 movss(Address(ESP, offs), src.AsXmmRegister());
1549 } else {
1550 movsd(Address(ESP, offs), src.AsXmmRegister());
1551 }
1552 }
1553}
1554
Ian Rogers2c8f6532011-09-02 17:16:34 -07001555void X86Assembler::StoreRef(FrameOffset dest, ManagedRegister msrc) {
1556 X86ManagedRegister src = msrc.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001557 CHECK(src.IsCpuRegister());
1558 movl(Address(ESP, dest), src.AsCpuRegister());
1559}
1560
Ian Rogers2c8f6532011-09-02 17:16:34 -07001561void X86Assembler::StoreRawPtr(FrameOffset dest, ManagedRegister msrc) {
1562 X86ManagedRegister src = msrc.AsX86();
Ian Rogersdf20fe02011-07-20 20:34:16 -07001563 CHECK(src.IsCpuRegister());
1564 movl(Address(ESP, dest), src.AsCpuRegister());
1565}
1566
Ian Rogers2c8f6532011-09-02 17:16:34 -07001567void X86Assembler::StoreImmediateToFrame(FrameOffset dest, uint32_t imm,
1568 ManagedRegister) {
Ian Rogersb033c752011-07-20 12:22:35 -07001569 movl(Address(ESP, dest), Immediate(imm));
1570}
1571
Ian Rogersdd7624d2014-03-14 17:43:00 -07001572void X86Assembler::StoreImmediateToThread32(ThreadOffset<4> dest, uint32_t imm,
Ian Rogers2c8f6532011-09-02 17:16:34 -07001573 ManagedRegister) {
Ian Rogers0d666d82011-08-14 16:03:46 -07001574 fs()->movl(Address::Absolute(dest), Immediate(imm));
Ian Rogersb033c752011-07-20 12:22:35 -07001575}
1576
Ian Rogersdd7624d2014-03-14 17:43:00 -07001577void X86Assembler::StoreStackOffsetToThread32(ThreadOffset<4> thr_offs,
Ian Rogers2c8f6532011-09-02 17:16:34 -07001578 FrameOffset fr_offs,
1579 ManagedRegister mscratch) {
1580 X86ManagedRegister scratch = mscratch.AsX86();
1581 CHECK(scratch.IsCpuRegister());
1582 leal(scratch.AsCpuRegister(), Address(ESP, fr_offs));
1583 fs()->movl(Address::Absolute(thr_offs), scratch.AsCpuRegister());
1584}
1585
Ian Rogersdd7624d2014-03-14 17:43:00 -07001586void X86Assembler::StoreStackPointerToThread32(ThreadOffset<4> thr_offs) {
Ian Rogers2c8f6532011-09-02 17:16:34 -07001587 fs()->movl(Address::Absolute(thr_offs), ESP);
1588}
1589
Elliott Hughes1bac54f2012-03-16 12:48:31 -07001590void X86Assembler::StoreSpanning(FrameOffset /*dst*/, ManagedRegister /*src*/,
1591 FrameOffset /*in_off*/, ManagedRegister /*scratch*/) {
Ian Rogers2c8f6532011-09-02 17:16:34 -07001592 UNIMPLEMENTED(FATAL); // this case only currently exists for ARM
1593}
1594
1595void X86Assembler::Load(ManagedRegister mdest, FrameOffset src, size_t size) {
1596 X86ManagedRegister dest = mdest.AsX86();
Ian Rogers45a76cb2011-07-21 22:00:15 -07001597 if (dest.IsNoRegister()) {
1598 CHECK_EQ(0u, size);
1599 } else if (dest.IsCpuRegister()) {
Ian Rogersb033c752011-07-20 12:22:35 -07001600 CHECK_EQ(4u, size);
1601 movl(dest.AsCpuRegister(), Address(ESP, src));
Ian Rogers9b269d22011-09-04 14:06:05 -07001602 } else if (dest.IsRegisterPair()) {
1603 CHECK_EQ(8u, size);
1604 movl(dest.AsRegisterPairLow(), Address(ESP, src));
1605 movl(dest.AsRegisterPairHigh(), Address(ESP, FrameOffset(src.Int32Value()+4)));
Ian Rogers45a76cb2011-07-21 22:00:15 -07001606 } else if (dest.IsX87Register()) {
1607 if (size == 4) {
1608 flds(Address(ESP, src));
1609 } else {
1610 fldl(Address(ESP, src));
1611 }
Ian Rogersb033c752011-07-20 12:22:35 -07001612 } else {
Ian Rogers45a76cb2011-07-21 22:00:15 -07001613 CHECK(dest.IsXmmRegister());
1614 if (size == 4) {
1615 movss(dest.AsXmmRegister(), Address(ESP, src));
1616 } else {
1617 movsd(dest.AsXmmRegister(), Address(ESP, src));
1618 }
Ian Rogersb033c752011-07-20 12:22:35 -07001619 }
1620}
1621
Ian Rogersdd7624d2014-03-14 17:43:00 -07001622void X86Assembler::LoadFromThread32(ManagedRegister mdest, ThreadOffset<4> src, size_t size) {
Ian Rogers5a7a74a2011-09-26 16:32:29 -07001623 X86ManagedRegister dest = mdest.AsX86();
1624 if (dest.IsNoRegister()) {
1625 CHECK_EQ(0u, size);
1626 } else if (dest.IsCpuRegister()) {
1627 CHECK_EQ(4u, size);
1628 fs()->movl(dest.AsCpuRegister(), Address::Absolute(src));
1629 } else if (dest.IsRegisterPair()) {
1630 CHECK_EQ(8u, size);
1631 fs()->movl(dest.AsRegisterPairLow(), Address::Absolute(src));
Ian Rogersdd7624d2014-03-14 17:43:00 -07001632 fs()->movl(dest.AsRegisterPairHigh(), Address::Absolute(ThreadOffset<4>(src.Int32Value()+4)));
Ian Rogers5a7a74a2011-09-26 16:32:29 -07001633 } else if (dest.IsX87Register()) {
1634 if (size == 4) {
1635 fs()->flds(Address::Absolute(src));
1636 } else {
1637 fs()->fldl(Address::Absolute(src));
1638 }
1639 } else {
1640 CHECK(dest.IsXmmRegister());
1641 if (size == 4) {
1642 fs()->movss(dest.AsXmmRegister(), Address::Absolute(src));
1643 } else {
1644 fs()->movsd(dest.AsXmmRegister(), Address::Absolute(src));
1645 }
1646 }
1647}
1648
Ian Rogers2c8f6532011-09-02 17:16:34 -07001649void X86Assembler::LoadRef(ManagedRegister mdest, FrameOffset src) {
1650 X86ManagedRegister dest = mdest.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001651 CHECK(dest.IsCpuRegister());
1652 movl(dest.AsCpuRegister(), Address(ESP, src));
1653}
1654
Ian Rogers2c8f6532011-09-02 17:16:34 -07001655void X86Assembler::LoadRef(ManagedRegister mdest, ManagedRegister base,
1656 MemberOffset offs) {
1657 X86ManagedRegister dest = mdest.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001658 CHECK(dest.IsCpuRegister() && dest.IsCpuRegister());
Ian Rogers2c8f6532011-09-02 17:16:34 -07001659 movl(dest.AsCpuRegister(), Address(base.AsX86().AsCpuRegister(), offs));
Hiroshi Yamauchie63a7452014-02-27 14:44:36 -08001660 if (kPoisonHeapReferences) {
1661 negl(dest.AsCpuRegister());
1662 }
Ian Rogersb033c752011-07-20 12:22:35 -07001663}
1664
Ian Rogers2c8f6532011-09-02 17:16:34 -07001665void X86Assembler::LoadRawPtr(ManagedRegister mdest, ManagedRegister base,
1666 Offset offs) {
1667 X86ManagedRegister dest = mdest.AsX86();
Ian Rogersa04d3972011-08-17 11:33:44 -07001668 CHECK(dest.IsCpuRegister() && dest.IsCpuRegister());
Ian Rogers2c8f6532011-09-02 17:16:34 -07001669 movl(dest.AsCpuRegister(), Address(base.AsX86().AsCpuRegister(), offs));
Ian Rogersa04d3972011-08-17 11:33:44 -07001670}
1671
Ian Rogersdd7624d2014-03-14 17:43:00 -07001672void X86Assembler::LoadRawPtrFromThread32(ManagedRegister mdest,
1673 ThreadOffset<4> offs) {
Ian Rogers2c8f6532011-09-02 17:16:34 -07001674 X86ManagedRegister dest = mdest.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001675 CHECK(dest.IsCpuRegister());
Ian Rogers0d666d82011-08-14 16:03:46 -07001676 fs()->movl(dest.AsCpuRegister(), Address::Absolute(offs));
Ian Rogersb033c752011-07-20 12:22:35 -07001677}
1678
jeffhao58136ca2012-05-24 13:40:11 -07001679void X86Assembler::SignExtend(ManagedRegister mreg, size_t size) {
1680 X86ManagedRegister reg = mreg.AsX86();
1681 CHECK(size == 1 || size == 2) << size;
1682 CHECK(reg.IsCpuRegister()) << reg;
1683 if (size == 1) {
1684 movsxb(reg.AsCpuRegister(), reg.AsByteRegister());
1685 } else {
1686 movsxw(reg.AsCpuRegister(), reg.AsCpuRegister());
1687 }
1688}
1689
jeffhaocee4d0c2012-06-15 14:42:01 -07001690void X86Assembler::ZeroExtend(ManagedRegister mreg, size_t size) {
1691 X86ManagedRegister reg = mreg.AsX86();
1692 CHECK(size == 1 || size == 2) << size;
1693 CHECK(reg.IsCpuRegister()) << reg;
1694 if (size == 1) {
1695 movzxb(reg.AsCpuRegister(), reg.AsByteRegister());
1696 } else {
1697 movzxw(reg.AsCpuRegister(), reg.AsCpuRegister());
1698 }
1699}
1700
Ian Rogersb5d09b22012-03-06 22:14:17 -08001701void X86Assembler::Move(ManagedRegister mdest, ManagedRegister msrc, size_t size) {
Ian Rogers2c8f6532011-09-02 17:16:34 -07001702 X86ManagedRegister dest = mdest.AsX86();
1703 X86ManagedRegister src = msrc.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001704 if (!dest.Equals(src)) {
1705 if (dest.IsCpuRegister() && src.IsCpuRegister()) {
1706 movl(dest.AsCpuRegister(), src.AsCpuRegister());
Ian Rogersb5d09b22012-03-06 22:14:17 -08001707 } else if (src.IsX87Register() && dest.IsXmmRegister()) {
1708 // Pass via stack and pop X87 register
1709 subl(ESP, Immediate(16));
1710 if (size == 4) {
1711 CHECK_EQ(src.AsX87Register(), ST0);
1712 fstps(Address(ESP, 0));
1713 movss(dest.AsXmmRegister(), Address(ESP, 0));
1714 } else {
1715 CHECK_EQ(src.AsX87Register(), ST0);
1716 fstpl(Address(ESP, 0));
1717 movsd(dest.AsXmmRegister(), Address(ESP, 0));
1718 }
1719 addl(ESP, Immediate(16));
Ian Rogersb033c752011-07-20 12:22:35 -07001720 } else {
1721 // TODO: x87, SSE
Ian Rogers2c8f6532011-09-02 17:16:34 -07001722 UNIMPLEMENTED(FATAL) << ": Move " << dest << ", " << src;
Ian Rogersb033c752011-07-20 12:22:35 -07001723 }
1724 }
1725}
1726
Ian Rogers2c8f6532011-09-02 17:16:34 -07001727void X86Assembler::CopyRef(FrameOffset dest, FrameOffset src,
1728 ManagedRegister mscratch) {
1729 X86ManagedRegister scratch = mscratch.AsX86();
1730 CHECK(scratch.IsCpuRegister());
1731 movl(scratch.AsCpuRegister(), Address(ESP, src));
1732 movl(Address(ESP, dest), scratch.AsCpuRegister());
1733}
1734
Ian Rogersdd7624d2014-03-14 17:43:00 -07001735void X86Assembler::CopyRawPtrFromThread32(FrameOffset fr_offs,
1736 ThreadOffset<4> thr_offs,
Ian Rogers2c8f6532011-09-02 17:16:34 -07001737 ManagedRegister mscratch) {
1738 X86ManagedRegister scratch = mscratch.AsX86();
1739 CHECK(scratch.IsCpuRegister());
1740 fs()->movl(scratch.AsCpuRegister(), Address::Absolute(thr_offs));
1741 Store(fr_offs, scratch, 4);
1742}
1743
Ian Rogersdd7624d2014-03-14 17:43:00 -07001744void X86Assembler::CopyRawPtrToThread32(ThreadOffset<4> thr_offs,
Ian Rogers2c8f6532011-09-02 17:16:34 -07001745 FrameOffset fr_offs,
1746 ManagedRegister mscratch) {
1747 X86ManagedRegister scratch = mscratch.AsX86();
1748 CHECK(scratch.IsCpuRegister());
1749 Load(scratch, fr_offs, 4);
1750 fs()->movl(Address::Absolute(thr_offs), scratch.AsCpuRegister());
1751}
1752
1753void X86Assembler::Copy(FrameOffset dest, FrameOffset src,
1754 ManagedRegister mscratch,
1755 size_t size) {
1756 X86ManagedRegister scratch = mscratch.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001757 if (scratch.IsCpuRegister() && size == 8) {
1758 Load(scratch, src, 4);
1759 Store(dest, scratch, 4);
1760 Load(scratch, FrameOffset(src.Int32Value() + 4), 4);
1761 Store(FrameOffset(dest.Int32Value() + 4), scratch, 4);
1762 } else {
1763 Load(scratch, src, size);
1764 Store(dest, scratch, size);
1765 }
1766}
1767
Elliott Hughes1bac54f2012-03-16 12:48:31 -07001768void X86Assembler::Copy(FrameOffset /*dst*/, ManagedRegister /*src_base*/, Offset /*src_offset*/,
1769 ManagedRegister /*scratch*/, size_t /*size*/) {
Ian Rogersdc51b792011-09-22 20:41:37 -07001770 UNIMPLEMENTED(FATAL);
1771}
1772
Ian Rogers5a7a74a2011-09-26 16:32:29 -07001773void X86Assembler::Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src,
1774 ManagedRegister scratch, size_t size) {
1775 CHECK(scratch.IsNoRegister());
1776 CHECK_EQ(size, 4u);
1777 pushl(Address(ESP, src));
1778 popl(Address(dest_base.AsX86().AsCpuRegister(), dest_offset));
1779}
1780
Ian Rogersdc51b792011-09-22 20:41:37 -07001781void X86Assembler::Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset,
1782 ManagedRegister mscratch, size_t size) {
1783 Register scratch = mscratch.AsX86().AsCpuRegister();
1784 CHECK_EQ(size, 4u);
1785 movl(scratch, Address(ESP, src_base));
1786 movl(scratch, Address(scratch, src_offset));
1787 movl(Address(ESP, dest), scratch);
1788}
1789
Ian Rogers5a7a74a2011-09-26 16:32:29 -07001790void X86Assembler::Copy(ManagedRegister dest, Offset dest_offset,
1791 ManagedRegister src, Offset src_offset,
1792 ManagedRegister scratch, size_t size) {
Ian Rogersdc51b792011-09-22 20:41:37 -07001793 CHECK_EQ(size, 4u);
Ian Rogers5a7a74a2011-09-26 16:32:29 -07001794 CHECK(scratch.IsNoRegister());
1795 pushl(Address(src.AsX86().AsCpuRegister(), src_offset));
1796 popl(Address(dest.AsX86().AsCpuRegister(), dest_offset));
1797}
1798
1799void X86Assembler::Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset,
1800 ManagedRegister mscratch, size_t size) {
1801 Register scratch = mscratch.AsX86().AsCpuRegister();
1802 CHECK_EQ(size, 4u);
1803 CHECK_EQ(dest.Int32Value(), src.Int32Value());
1804 movl(scratch, Address(ESP, src));
1805 pushl(Address(scratch, src_offset));
Ian Rogersdc51b792011-09-22 20:41:37 -07001806 popl(Address(scratch, dest_offset));
1807}
1808
Ian Rogerse5de95b2011-09-18 20:31:38 -07001809void X86Assembler::MemoryBarrier(ManagedRegister) {
1810#if ANDROID_SMP != 0
Elliott Hughes79ab9e32012-03-12 15:41:35 -07001811 mfence();
Ian Rogerse5de95b2011-09-18 20:31:38 -07001812#endif
1813}
1814
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001815void X86Assembler::CreateHandleScopeEntry(ManagedRegister mout_reg,
1816 FrameOffset handle_scope_offset,
Ian Rogers2c8f6532011-09-02 17:16:34 -07001817 ManagedRegister min_reg, bool null_allowed) {
1818 X86ManagedRegister out_reg = mout_reg.AsX86();
1819 X86ManagedRegister in_reg = min_reg.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001820 CHECK(in_reg.IsCpuRegister());
1821 CHECK(out_reg.IsCpuRegister());
Ian Rogers408f79a2011-08-23 18:22:33 -07001822 VerifyObject(in_reg, null_allowed);
Ian Rogersb033c752011-07-20 12:22:35 -07001823 if (null_allowed) {
1824 Label null_arg;
1825 if (!out_reg.Equals(in_reg)) {
1826 xorl(out_reg.AsCpuRegister(), out_reg.AsCpuRegister());
1827 }
1828 testl(in_reg.AsCpuRegister(), in_reg.AsCpuRegister());
Elliott Hughes18c07532011-08-18 15:50:51 -07001829 j(kZero, &null_arg);
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001830 leal(out_reg.AsCpuRegister(), Address(ESP, handle_scope_offset));
Ian Rogersb033c752011-07-20 12:22:35 -07001831 Bind(&null_arg);
1832 } else {
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001833 leal(out_reg.AsCpuRegister(), Address(ESP, handle_scope_offset));
Ian Rogersb033c752011-07-20 12:22:35 -07001834 }
1835}
1836
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001837void X86Assembler::CreateHandleScopeEntry(FrameOffset out_off,
1838 FrameOffset handle_scope_offset,
Ian Rogers2c8f6532011-09-02 17:16:34 -07001839 ManagedRegister mscratch,
1840 bool null_allowed) {
1841 X86ManagedRegister scratch = mscratch.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001842 CHECK(scratch.IsCpuRegister());
1843 if (null_allowed) {
1844 Label null_arg;
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001845 movl(scratch.AsCpuRegister(), Address(ESP, handle_scope_offset));
Ian Rogersb033c752011-07-20 12:22:35 -07001846 testl(scratch.AsCpuRegister(), scratch.AsCpuRegister());
Elliott Hughes18c07532011-08-18 15:50:51 -07001847 j(kZero, &null_arg);
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001848 leal(scratch.AsCpuRegister(), Address(ESP, handle_scope_offset));
Ian Rogersb033c752011-07-20 12:22:35 -07001849 Bind(&null_arg);
1850 } else {
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001851 leal(scratch.AsCpuRegister(), Address(ESP, handle_scope_offset));
Ian Rogersb033c752011-07-20 12:22:35 -07001852 }
1853 Store(out_off, scratch, 4);
1854}
1855
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001856// Given a handle scope entry, load the associated reference.
1857void X86Assembler::LoadReferenceFromHandleScope(ManagedRegister mout_reg,
Ian Rogers2c8f6532011-09-02 17:16:34 -07001858 ManagedRegister min_reg) {
1859 X86ManagedRegister out_reg = mout_reg.AsX86();
1860 X86ManagedRegister in_reg = min_reg.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001861 CHECK(out_reg.IsCpuRegister());
1862 CHECK(in_reg.IsCpuRegister());
1863 Label null_arg;
1864 if (!out_reg.Equals(in_reg)) {
1865 xorl(out_reg.AsCpuRegister(), out_reg.AsCpuRegister());
1866 }
1867 testl(in_reg.AsCpuRegister(), in_reg.AsCpuRegister());
Elliott Hughes18c07532011-08-18 15:50:51 -07001868 j(kZero, &null_arg);
Ian Rogersb033c752011-07-20 12:22:35 -07001869 movl(out_reg.AsCpuRegister(), Address(in_reg.AsCpuRegister(), 0));
1870 Bind(&null_arg);
1871}
1872
Elliott Hughes1bac54f2012-03-16 12:48:31 -07001873void X86Assembler::VerifyObject(ManagedRegister /*src*/, bool /*could_be_null*/) {
Ian Rogersb033c752011-07-20 12:22:35 -07001874 // TODO: not validating references
1875}
1876
Elliott Hughes1bac54f2012-03-16 12:48:31 -07001877void X86Assembler::VerifyObject(FrameOffset /*src*/, bool /*could_be_null*/) {
Ian Rogersb033c752011-07-20 12:22:35 -07001878 // TODO: not validating references
1879}
1880
Ian Rogers2c8f6532011-09-02 17:16:34 -07001881void X86Assembler::Call(ManagedRegister mbase, Offset offset, ManagedRegister) {
1882 X86ManagedRegister base = mbase.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001883 CHECK(base.IsCpuRegister());
Ian Rogersdf20fe02011-07-20 20:34:16 -07001884 call(Address(base.AsCpuRegister(), offset.Int32Value()));
Ian Rogersb033c752011-07-20 12:22:35 -07001885 // TODO: place reference map on call
1886}
1887
Ian Rogers67375ac2011-09-14 00:55:44 -07001888void X86Assembler::Call(FrameOffset base, Offset offset, ManagedRegister mscratch) {
1889 Register scratch = mscratch.AsX86().AsCpuRegister();
1890 movl(scratch, Address(ESP, base));
1891 call(Address(scratch, offset));
Carl Shapiroe2d373e2011-07-25 15:20:06 -07001892}
1893
Ian Rogersdd7624d2014-03-14 17:43:00 -07001894void X86Assembler::CallFromThread32(ThreadOffset<4> offset, ManagedRegister /*mscratch*/) {
Ian Rogersbdb03912011-09-14 00:55:44 -07001895 fs()->call(Address::Absolute(offset));
Shih-wei Liao668512a2011-09-01 14:18:34 -07001896}
1897
Ian Rogers2c8f6532011-09-02 17:16:34 -07001898void X86Assembler::GetCurrentThread(ManagedRegister tr) {
1899 fs()->movl(tr.AsX86().AsCpuRegister(),
Ian Rogersdd7624d2014-03-14 17:43:00 -07001900 Address::Absolute(Thread::SelfOffset<4>()));
Shih-wei Liao668512a2011-09-01 14:18:34 -07001901}
1902
Ian Rogers2c8f6532011-09-02 17:16:34 -07001903void X86Assembler::GetCurrentThread(FrameOffset offset,
1904 ManagedRegister mscratch) {
1905 X86ManagedRegister scratch = mscratch.AsX86();
Ian Rogersdd7624d2014-03-14 17:43:00 -07001906 fs()->movl(scratch.AsCpuRegister(), Address::Absolute(Thread::SelfOffset<4>()));
Shih-wei Liao668512a2011-09-01 14:18:34 -07001907 movl(Address(ESP, offset), scratch.AsCpuRegister());
1908}
1909
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001910void X86Assembler::ExceptionPoll(ManagedRegister /*scratch*/, size_t stack_adjust) {
1911 X86ExceptionSlowPath* slow = new X86ExceptionSlowPath(stack_adjust);
Ian Rogers45a76cb2011-07-21 22:00:15 -07001912 buffer_.EnqueueSlowPath(slow);
Ian Rogersdd7624d2014-03-14 17:43:00 -07001913 fs()->cmpl(Address::Absolute(Thread::ExceptionOffset<4>()), Immediate(0));
Elliott Hughes18c07532011-08-18 15:50:51 -07001914 j(kNotEqual, slow->Entry());
Ian Rogers45a76cb2011-07-21 22:00:15 -07001915}
Ian Rogers0d666d82011-08-14 16:03:46 -07001916
Ian Rogers2c8f6532011-09-02 17:16:34 -07001917void X86ExceptionSlowPath::Emit(Assembler *sasm) {
1918 X86Assembler* sp_asm = down_cast<X86Assembler*>(sasm);
Ian Rogers0d666d82011-08-14 16:03:46 -07001919#define __ sp_asm->
1920 __ Bind(&entry_);
Elliott Hughes20cde902011-10-04 17:37:27 -07001921 // Note: the return value is dead
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001922 if (stack_adjust_ != 0) { // Fix up the frame.
1923 __ DecreaseFrameSize(stack_adjust_);
1924 }
Ian Rogers67375ac2011-09-14 00:55:44 -07001925 // Pass exception as argument in EAX
Ian Rogersdd7624d2014-03-14 17:43:00 -07001926 __ fs()->movl(EAX, Address::Absolute(Thread::ExceptionOffset<4>()));
1927 __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(4, pDeliverException)));
Ian Rogers67375ac2011-09-14 00:55:44 -07001928 // this call should never return
1929 __ int3();
Ian Rogers0d666d82011-08-14 16:03:46 -07001930#undef __
Ian Rogers45a76cb2011-07-21 22:00:15 -07001931}
1932
Ian Rogers2c8f6532011-09-02 17:16:34 -07001933} // namespace x86
Ian Rogersb033c752011-07-20 12:22:35 -07001934} // namespace art