blob: ea283ceaec13a24095e0e13cc5a49ae6f310002b [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
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070019#include "casts.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070020#include "memory_region.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070021#include "thread.h"
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070022
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070023namespace art {
Ian Rogers2c8f6532011-09-02 17:16:34 -070024namespace x86 {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070025
26class DirectCallRelocation : public AssemblerFixup {
27 public:
28 void Process(const MemoryRegion& region, int position) {
29 // Direct calls are relative to the following instruction on x86.
30 int32_t pointer = region.Load<int32_t>(position);
31 int32_t start = reinterpret_cast<int32_t>(region.start());
32 int32_t delta = start + position + sizeof(int32_t);
33 region.Store<int32_t>(position, pointer - delta);
34 }
35};
36
Elliott Hughes1f359b02011-07-17 14:27:17 -070037static const char* kRegisterNames[] = {
38 "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
39};
40std::ostream& operator<<(std::ostream& os, const Register& rhs) {
41 if (rhs >= EAX && rhs <= EDI) {
42 os << kRegisterNames[rhs];
43 } else {
Ian Rogersb033c752011-07-20 12:22:35 -070044 os << "Register[" << static_cast<int>(rhs) << "]";
Elliott Hughes1f359b02011-07-17 14:27:17 -070045 }
46 return os;
47}
48
Ian Rogersb033c752011-07-20 12:22:35 -070049std::ostream& operator<<(std::ostream& os, const XmmRegister& reg) {
50 return os << "XMM" << static_cast<int>(reg);
51}
52
53std::ostream& operator<<(std::ostream& os, const X87Register& reg) {
54 return os << "ST" << static_cast<int>(reg);
55}
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070056
Ian Rogers2c8f6532011-09-02 17:16:34 -070057void X86Assembler::call(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070058 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
59 EmitUint8(0xFF);
60 EmitRegisterOperand(2, reg);
61}
62
63
Ian Rogers2c8f6532011-09-02 17:16:34 -070064void X86Assembler::call(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070065 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
66 EmitUint8(0xFF);
67 EmitOperand(2, address);
68}
69
70
Ian Rogers2c8f6532011-09-02 17:16:34 -070071void X86Assembler::call(Label* label) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070072 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
73 EmitUint8(0xE8);
74 static const int kSize = 5;
75 EmitLabel(label, kSize);
76}
77
78
Ian Rogers2c8f6532011-09-02 17:16:34 -070079void X86Assembler::pushl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070080 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
81 EmitUint8(0x50 + reg);
82}
83
84
Ian Rogers2c8f6532011-09-02 17:16:34 -070085void X86Assembler::pushl(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070086 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
87 EmitUint8(0xFF);
88 EmitOperand(6, address);
89}
90
91
Ian Rogers2c8f6532011-09-02 17:16:34 -070092void X86Assembler::pushl(const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070093 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
Ian Rogers44fb0d02012-03-23 16:46:24 -070094 if (imm.is_int8()) {
95 EmitUint8(0x6A);
96 EmitUint8(imm.value() & 0xFF);
97 } else {
98 EmitUint8(0x68);
99 EmitImmediate(imm);
100 }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700101}
102
103
Ian Rogers2c8f6532011-09-02 17:16:34 -0700104void X86Assembler::popl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700105 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
106 EmitUint8(0x58 + reg);
107}
108
109
Ian Rogers2c8f6532011-09-02 17:16:34 -0700110void X86Assembler::popl(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700111 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
112 EmitUint8(0x8F);
113 EmitOperand(0, address);
114}
115
116
Ian Rogers2c8f6532011-09-02 17:16:34 -0700117void X86Assembler::movl(Register dst, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700118 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
119 EmitUint8(0xB8 + dst);
120 EmitImmediate(imm);
121}
122
123
Ian Rogers2c8f6532011-09-02 17:16:34 -0700124void X86Assembler::movl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700125 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
126 EmitUint8(0x89);
127 EmitRegisterOperand(src, dst);
128}
129
130
Ian Rogers2c8f6532011-09-02 17:16:34 -0700131void X86Assembler::movl(Register dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700132 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
133 EmitUint8(0x8B);
134 EmitOperand(dst, src);
135}
136
137
Ian Rogers2c8f6532011-09-02 17:16:34 -0700138void X86Assembler::movl(const Address& dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700139 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
140 EmitUint8(0x89);
141 EmitOperand(src, dst);
142}
143
144
Ian Rogers2c8f6532011-09-02 17:16:34 -0700145void X86Assembler::movl(const Address& dst, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700146 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
147 EmitUint8(0xC7);
148 EmitOperand(0, dst);
149 EmitImmediate(imm);
150}
151
Ian Rogersbdb03912011-09-14 00:55:44 -0700152void X86Assembler::movl(const Address& dst, Label* lbl) {
153 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
154 EmitUint8(0xC7);
155 EmitOperand(0, dst);
156 EmitLabel(lbl, dst.length_ + 5);
157}
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700158
Ian Rogers2c8f6532011-09-02 17:16:34 -0700159void X86Assembler::movzxb(Register dst, ByteRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700160 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
161 EmitUint8(0x0F);
162 EmitUint8(0xB6);
163 EmitRegisterOperand(dst, src);
164}
165
166
Ian Rogers2c8f6532011-09-02 17:16:34 -0700167void X86Assembler::movzxb(Register dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700168 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
169 EmitUint8(0x0F);
170 EmitUint8(0xB6);
171 EmitOperand(dst, src);
172}
173
174
Ian Rogers2c8f6532011-09-02 17:16:34 -0700175void X86Assembler::movsxb(Register dst, ByteRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700176 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
177 EmitUint8(0x0F);
178 EmitUint8(0xBE);
179 EmitRegisterOperand(dst, src);
180}
181
182
Ian Rogers2c8f6532011-09-02 17:16:34 -0700183void X86Assembler::movsxb(Register dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700184 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
185 EmitUint8(0x0F);
186 EmitUint8(0xBE);
187 EmitOperand(dst, src);
188}
189
190
Elliott Hughes1bac54f2012-03-16 12:48:31 -0700191void X86Assembler::movb(Register /*dst*/, const Address& /*src*/) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700192 LOG(FATAL) << "Use movzxb or movsxb instead.";
193}
194
195
Ian Rogers2c8f6532011-09-02 17:16:34 -0700196void X86Assembler::movb(const Address& dst, ByteRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700197 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
198 EmitUint8(0x88);
199 EmitOperand(src, dst);
200}
201
202
Ian Rogers2c8f6532011-09-02 17:16:34 -0700203void X86Assembler::movb(const Address& dst, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700204 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
205 EmitUint8(0xC6);
206 EmitOperand(EAX, dst);
207 CHECK(imm.is_int8());
208 EmitUint8(imm.value() & 0xFF);
209}
210
211
Ian Rogers2c8f6532011-09-02 17:16:34 -0700212void X86Assembler::movzxw(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700213 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
214 EmitUint8(0x0F);
215 EmitUint8(0xB7);
216 EmitRegisterOperand(dst, src);
217}
218
219
Ian Rogers2c8f6532011-09-02 17:16:34 -0700220void X86Assembler::movzxw(Register dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700221 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
222 EmitUint8(0x0F);
223 EmitUint8(0xB7);
224 EmitOperand(dst, src);
225}
226
227
Ian Rogers2c8f6532011-09-02 17:16:34 -0700228void X86Assembler::movsxw(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700229 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
230 EmitUint8(0x0F);
231 EmitUint8(0xBF);
232 EmitRegisterOperand(dst, src);
233}
234
235
Ian Rogers2c8f6532011-09-02 17:16:34 -0700236void X86Assembler::movsxw(Register dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700237 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
238 EmitUint8(0x0F);
239 EmitUint8(0xBF);
240 EmitOperand(dst, src);
241}
242
243
Elliott Hughes1bac54f2012-03-16 12:48:31 -0700244void X86Assembler::movw(Register /*dst*/, const Address& /*src*/) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700245 LOG(FATAL) << "Use movzxw or movsxw instead.";
246}
247
248
Ian Rogers2c8f6532011-09-02 17:16:34 -0700249void X86Assembler::movw(const Address& dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700250 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
251 EmitOperandSizeOverride();
252 EmitUint8(0x89);
253 EmitOperand(src, dst);
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
Ian Rogers2c8f6532011-09-02 17:16:34 -0700280void X86Assembler::movss(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700281 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
282 EmitUint8(0xF3);
283 EmitUint8(0x0F);
284 EmitUint8(0x10);
285 EmitOperand(dst, src);
286}
287
288
Ian Rogers2c8f6532011-09-02 17:16:34 -0700289void X86Assembler::movss(const Address& dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700290 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
291 EmitUint8(0xF3);
292 EmitUint8(0x0F);
293 EmitUint8(0x11);
294 EmitOperand(src, dst);
295}
296
297
Ian Rogers2c8f6532011-09-02 17:16:34 -0700298void X86Assembler::movss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700299 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
300 EmitUint8(0xF3);
301 EmitUint8(0x0F);
302 EmitUint8(0x11);
303 EmitXmmRegisterOperand(src, dst);
304}
305
306
Ian Rogers2c8f6532011-09-02 17:16:34 -0700307void X86Assembler::movd(XmmRegister dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700308 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
309 EmitUint8(0x66);
310 EmitUint8(0x0F);
311 EmitUint8(0x6E);
312 EmitOperand(dst, Operand(src));
313}
314
315
Ian Rogers2c8f6532011-09-02 17:16:34 -0700316void X86Assembler::movd(Register dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700317 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
318 EmitUint8(0x66);
319 EmitUint8(0x0F);
320 EmitUint8(0x7E);
321 EmitOperand(src, Operand(dst));
322}
323
324
Ian Rogers2c8f6532011-09-02 17:16:34 -0700325void X86Assembler::addss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700326 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
327 EmitUint8(0xF3);
328 EmitUint8(0x0F);
329 EmitUint8(0x58);
330 EmitXmmRegisterOperand(dst, src);
331}
332
333
Ian Rogers2c8f6532011-09-02 17:16:34 -0700334void X86Assembler::addss(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700335 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
336 EmitUint8(0xF3);
337 EmitUint8(0x0F);
338 EmitUint8(0x58);
339 EmitOperand(dst, src);
340}
341
342
Ian Rogers2c8f6532011-09-02 17:16:34 -0700343void X86Assembler::subss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700344 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
345 EmitUint8(0xF3);
346 EmitUint8(0x0F);
347 EmitUint8(0x5C);
348 EmitXmmRegisterOperand(dst, src);
349}
350
351
Ian Rogers2c8f6532011-09-02 17:16:34 -0700352void X86Assembler::subss(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700353 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
354 EmitUint8(0xF3);
355 EmitUint8(0x0F);
356 EmitUint8(0x5C);
357 EmitOperand(dst, src);
358}
359
360
Ian Rogers2c8f6532011-09-02 17:16:34 -0700361void X86Assembler::mulss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700362 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
363 EmitUint8(0xF3);
364 EmitUint8(0x0F);
365 EmitUint8(0x59);
366 EmitXmmRegisterOperand(dst, src);
367}
368
369
Ian Rogers2c8f6532011-09-02 17:16:34 -0700370void X86Assembler::mulss(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700371 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
372 EmitUint8(0xF3);
373 EmitUint8(0x0F);
374 EmitUint8(0x59);
375 EmitOperand(dst, src);
376}
377
378
Ian Rogers2c8f6532011-09-02 17:16:34 -0700379void X86Assembler::divss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700380 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
381 EmitUint8(0xF3);
382 EmitUint8(0x0F);
383 EmitUint8(0x5E);
384 EmitXmmRegisterOperand(dst, src);
385}
386
387
Ian Rogers2c8f6532011-09-02 17:16:34 -0700388void X86Assembler::divss(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700389 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
390 EmitUint8(0xF3);
391 EmitUint8(0x0F);
392 EmitUint8(0x5E);
393 EmitOperand(dst, src);
394}
395
396
Ian Rogers2c8f6532011-09-02 17:16:34 -0700397void X86Assembler::flds(const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700398 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
399 EmitUint8(0xD9);
400 EmitOperand(0, src);
401}
402
403
Ian Rogers2c8f6532011-09-02 17:16:34 -0700404void X86Assembler::fstps(const Address& dst) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700405 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
406 EmitUint8(0xD9);
407 EmitOperand(3, dst);
408}
409
410
Ian Rogers2c8f6532011-09-02 17:16:34 -0700411void X86Assembler::movsd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700412 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
413 EmitUint8(0xF2);
414 EmitUint8(0x0F);
415 EmitUint8(0x10);
416 EmitOperand(dst, src);
417}
418
419
Ian Rogers2c8f6532011-09-02 17:16:34 -0700420void X86Assembler::movsd(const Address& dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700421 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
422 EmitUint8(0xF2);
423 EmitUint8(0x0F);
424 EmitUint8(0x11);
425 EmitOperand(src, dst);
426}
427
428
Ian Rogers2c8f6532011-09-02 17:16:34 -0700429void X86Assembler::movsd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700430 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
431 EmitUint8(0xF2);
432 EmitUint8(0x0F);
433 EmitUint8(0x11);
434 EmitXmmRegisterOperand(src, dst);
435}
436
437
Ian Rogers2c8f6532011-09-02 17:16:34 -0700438void X86Assembler::addsd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700439 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
440 EmitUint8(0xF2);
441 EmitUint8(0x0F);
442 EmitUint8(0x58);
443 EmitXmmRegisterOperand(dst, src);
444}
445
446
Ian Rogers2c8f6532011-09-02 17:16:34 -0700447void X86Assembler::addsd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700448 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
449 EmitUint8(0xF2);
450 EmitUint8(0x0F);
451 EmitUint8(0x58);
452 EmitOperand(dst, src);
453}
454
455
Ian Rogers2c8f6532011-09-02 17:16:34 -0700456void X86Assembler::subsd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700457 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
458 EmitUint8(0xF2);
459 EmitUint8(0x0F);
460 EmitUint8(0x5C);
461 EmitXmmRegisterOperand(dst, src);
462}
463
464
Ian Rogers2c8f6532011-09-02 17:16:34 -0700465void X86Assembler::subsd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700466 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
467 EmitUint8(0xF2);
468 EmitUint8(0x0F);
469 EmitUint8(0x5C);
470 EmitOperand(dst, src);
471}
472
473
Ian Rogers2c8f6532011-09-02 17:16:34 -0700474void X86Assembler::mulsd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700475 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
476 EmitUint8(0xF2);
477 EmitUint8(0x0F);
478 EmitUint8(0x59);
479 EmitXmmRegisterOperand(dst, src);
480}
481
482
Ian Rogers2c8f6532011-09-02 17:16:34 -0700483void X86Assembler::mulsd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700484 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
485 EmitUint8(0xF2);
486 EmitUint8(0x0F);
487 EmitUint8(0x59);
488 EmitOperand(dst, src);
489}
490
491
Ian Rogers2c8f6532011-09-02 17:16:34 -0700492void X86Assembler::divsd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700493 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
494 EmitUint8(0xF2);
495 EmitUint8(0x0F);
496 EmitUint8(0x5E);
497 EmitXmmRegisterOperand(dst, src);
498}
499
500
Ian Rogers2c8f6532011-09-02 17:16:34 -0700501void X86Assembler::divsd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700502 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
503 EmitUint8(0xF2);
504 EmitUint8(0x0F);
505 EmitUint8(0x5E);
506 EmitOperand(dst, src);
507}
508
509
Ian Rogers2c8f6532011-09-02 17:16:34 -0700510void X86Assembler::cvtsi2ss(XmmRegister dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700511 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
512 EmitUint8(0xF3);
513 EmitUint8(0x0F);
514 EmitUint8(0x2A);
515 EmitOperand(dst, Operand(src));
516}
517
518
Ian Rogers2c8f6532011-09-02 17:16:34 -0700519void X86Assembler::cvtsi2sd(XmmRegister dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700520 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
521 EmitUint8(0xF2);
522 EmitUint8(0x0F);
523 EmitUint8(0x2A);
524 EmitOperand(dst, Operand(src));
525}
526
527
Ian Rogers2c8f6532011-09-02 17:16:34 -0700528void X86Assembler::cvtss2si(Register dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700529 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
530 EmitUint8(0xF3);
531 EmitUint8(0x0F);
532 EmitUint8(0x2D);
533 EmitXmmRegisterOperand(dst, src);
534}
535
536
Ian Rogers2c8f6532011-09-02 17:16:34 -0700537void X86Assembler::cvtss2sd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700538 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
539 EmitUint8(0xF3);
540 EmitUint8(0x0F);
541 EmitUint8(0x5A);
542 EmitXmmRegisterOperand(dst, src);
543}
544
545
Ian Rogers2c8f6532011-09-02 17:16:34 -0700546void X86Assembler::cvtsd2si(Register dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700547 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
548 EmitUint8(0xF2);
549 EmitUint8(0x0F);
550 EmitUint8(0x2D);
551 EmitXmmRegisterOperand(dst, src);
552}
553
554
Ian Rogers2c8f6532011-09-02 17:16:34 -0700555void X86Assembler::cvttss2si(Register dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700556 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
557 EmitUint8(0xF3);
558 EmitUint8(0x0F);
559 EmitUint8(0x2C);
560 EmitXmmRegisterOperand(dst, src);
561}
562
563
Ian Rogers2c8f6532011-09-02 17:16:34 -0700564void X86Assembler::cvttsd2si(Register dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700565 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
566 EmitUint8(0xF2);
567 EmitUint8(0x0F);
568 EmitUint8(0x2C);
569 EmitXmmRegisterOperand(dst, src);
570}
571
572
Ian Rogers2c8f6532011-09-02 17:16:34 -0700573void X86Assembler::cvtsd2ss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700574 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
575 EmitUint8(0xF2);
576 EmitUint8(0x0F);
577 EmitUint8(0x5A);
578 EmitXmmRegisterOperand(dst, src);
579}
580
581
Ian Rogers2c8f6532011-09-02 17:16:34 -0700582void X86Assembler::cvtdq2pd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700583 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
584 EmitUint8(0xF3);
585 EmitUint8(0x0F);
586 EmitUint8(0xE6);
587 EmitXmmRegisterOperand(dst, src);
588}
589
590
Ian Rogers2c8f6532011-09-02 17:16:34 -0700591void X86Assembler::comiss(XmmRegister a, XmmRegister b) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700592 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
593 EmitUint8(0x0F);
594 EmitUint8(0x2F);
595 EmitXmmRegisterOperand(a, b);
596}
597
598
Ian Rogers2c8f6532011-09-02 17:16:34 -0700599void X86Assembler::comisd(XmmRegister a, XmmRegister b) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700600 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
601 EmitUint8(0x66);
602 EmitUint8(0x0F);
603 EmitUint8(0x2F);
604 EmitXmmRegisterOperand(a, b);
605}
606
607
Ian Rogers2c8f6532011-09-02 17:16:34 -0700608void X86Assembler::sqrtsd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700609 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
610 EmitUint8(0xF2);
611 EmitUint8(0x0F);
612 EmitUint8(0x51);
613 EmitXmmRegisterOperand(dst, src);
614}
615
616
Ian Rogers2c8f6532011-09-02 17:16:34 -0700617void X86Assembler::sqrtss(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700618 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
619 EmitUint8(0xF3);
620 EmitUint8(0x0F);
621 EmitUint8(0x51);
622 EmitXmmRegisterOperand(dst, src);
623}
624
625
Ian Rogers2c8f6532011-09-02 17:16:34 -0700626void X86Assembler::xorpd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700627 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
628 EmitUint8(0x66);
629 EmitUint8(0x0F);
630 EmitUint8(0x57);
631 EmitOperand(dst, src);
632}
633
634
Ian Rogers2c8f6532011-09-02 17:16:34 -0700635void X86Assembler::xorpd(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700636 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
637 EmitUint8(0x66);
638 EmitUint8(0x0F);
639 EmitUint8(0x57);
640 EmitXmmRegisterOperand(dst, src);
641}
642
643
Ian Rogers2c8f6532011-09-02 17:16:34 -0700644void X86Assembler::xorps(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700645 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
646 EmitUint8(0x0F);
647 EmitUint8(0x57);
648 EmitOperand(dst, src);
649}
650
651
Ian Rogers2c8f6532011-09-02 17:16:34 -0700652void X86Assembler::xorps(XmmRegister dst, XmmRegister src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700653 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
654 EmitUint8(0x0F);
655 EmitUint8(0x57);
656 EmitXmmRegisterOperand(dst, src);
657}
658
659
Ian Rogers2c8f6532011-09-02 17:16:34 -0700660void X86Assembler::andpd(XmmRegister dst, const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700661 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
662 EmitUint8(0x66);
663 EmitUint8(0x0F);
664 EmitUint8(0x54);
665 EmitOperand(dst, src);
666}
667
668
Ian Rogers2c8f6532011-09-02 17:16:34 -0700669void X86Assembler::fldl(const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700670 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
671 EmitUint8(0xDD);
672 EmitOperand(0, src);
673}
674
675
Ian Rogers2c8f6532011-09-02 17:16:34 -0700676void X86Assembler::fstpl(const Address& dst) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700677 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
678 EmitUint8(0xDD);
679 EmitOperand(3, dst);
680}
681
682
Ian Rogers2c8f6532011-09-02 17:16:34 -0700683void X86Assembler::fnstcw(const Address& dst) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700684 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
685 EmitUint8(0xD9);
686 EmitOperand(7, dst);
687}
688
689
Ian Rogers2c8f6532011-09-02 17:16:34 -0700690void X86Assembler::fldcw(const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700691 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
692 EmitUint8(0xD9);
693 EmitOperand(5, src);
694}
695
696
Ian Rogers2c8f6532011-09-02 17:16:34 -0700697void X86Assembler::fistpl(const Address& dst) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700698 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
699 EmitUint8(0xDF);
700 EmitOperand(7, dst);
701}
702
703
Ian Rogers2c8f6532011-09-02 17:16:34 -0700704void X86Assembler::fistps(const Address& dst) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700705 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
706 EmitUint8(0xDB);
707 EmitOperand(3, dst);
708}
709
710
Ian Rogers2c8f6532011-09-02 17:16:34 -0700711void X86Assembler::fildl(const Address& src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700712 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
713 EmitUint8(0xDF);
714 EmitOperand(5, src);
715}
716
717
Ian Rogers2c8f6532011-09-02 17:16:34 -0700718void X86Assembler::fincstp() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700719 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
720 EmitUint8(0xD9);
721 EmitUint8(0xF7);
722}
723
724
Ian Rogers2c8f6532011-09-02 17:16:34 -0700725void X86Assembler::ffree(const Immediate& index) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700726 CHECK_LT(index.value(), 7);
727 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
728 EmitUint8(0xDD);
729 EmitUint8(0xC0 + index.value());
730}
731
732
Ian Rogers2c8f6532011-09-02 17:16:34 -0700733void X86Assembler::fsin() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700734 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
735 EmitUint8(0xD9);
736 EmitUint8(0xFE);
737}
738
739
Ian Rogers2c8f6532011-09-02 17:16:34 -0700740void X86Assembler::fcos() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700741 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
742 EmitUint8(0xD9);
743 EmitUint8(0xFF);
744}
745
746
Ian Rogers2c8f6532011-09-02 17:16:34 -0700747void X86Assembler::fptan() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700748 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
749 EmitUint8(0xD9);
750 EmitUint8(0xF2);
751}
752
753
Ian Rogers2c8f6532011-09-02 17:16:34 -0700754void X86Assembler::xchgl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700755 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
756 EmitUint8(0x87);
757 EmitRegisterOperand(dst, src);
758}
759
760
Ian Rogers2c8f6532011-09-02 17:16:34 -0700761void X86Assembler::cmpl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700762 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
763 EmitComplex(7, Operand(reg), imm);
764}
765
766
Ian Rogers2c8f6532011-09-02 17:16:34 -0700767void X86Assembler::cmpl(Register reg0, Register reg1) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700768 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
769 EmitUint8(0x3B);
770 EmitOperand(reg0, Operand(reg1));
771}
772
773
Ian Rogers2c8f6532011-09-02 17:16:34 -0700774void X86Assembler::cmpl(Register reg, const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700775 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
776 EmitUint8(0x3B);
777 EmitOperand(reg, address);
778}
779
780
Ian Rogers2c8f6532011-09-02 17:16:34 -0700781void X86Assembler::addl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700782 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
783 EmitUint8(0x03);
784 EmitRegisterOperand(dst, src);
785}
786
787
Ian Rogers2c8f6532011-09-02 17:16:34 -0700788void X86Assembler::addl(Register reg, const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700789 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
790 EmitUint8(0x03);
791 EmitOperand(reg, address);
792}
793
794
Ian Rogers2c8f6532011-09-02 17:16:34 -0700795void X86Assembler::cmpl(const Address& address, Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700796 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
797 EmitUint8(0x39);
798 EmitOperand(reg, address);
799}
800
801
Ian Rogers2c8f6532011-09-02 17:16:34 -0700802void X86Assembler::cmpl(const Address& address, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700803 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
804 EmitComplex(7, address, imm);
805}
806
807
Ian Rogers2c8f6532011-09-02 17:16:34 -0700808void X86Assembler::testl(Register reg1, Register reg2) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700809 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
810 EmitUint8(0x85);
811 EmitRegisterOperand(reg1, reg2);
812}
813
814
Ian Rogers2c8f6532011-09-02 17:16:34 -0700815void X86Assembler::testl(Register reg, const Immediate& immediate) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700816 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
817 // For registers that have a byte variant (EAX, EBX, ECX, and EDX)
818 // we only test the byte register to keep the encoding short.
819 if (immediate.is_uint8() && reg < 4) {
820 // Use zero-extended 8-bit immediate.
821 if (reg == EAX) {
822 EmitUint8(0xA8);
823 } else {
824 EmitUint8(0xF6);
825 EmitUint8(0xC0 + reg);
826 }
827 EmitUint8(immediate.value() & 0xFF);
828 } else if (reg == EAX) {
829 // Use short form if the destination is EAX.
830 EmitUint8(0xA9);
831 EmitImmediate(immediate);
832 } else {
833 EmitUint8(0xF7);
834 EmitOperand(0, Operand(reg));
835 EmitImmediate(immediate);
836 }
837}
838
839
Ian Rogers2c8f6532011-09-02 17:16:34 -0700840void X86Assembler::andl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700841 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
842 EmitUint8(0x23);
843 EmitOperand(dst, Operand(src));
844}
845
846
Ian Rogers2c8f6532011-09-02 17:16:34 -0700847void X86Assembler::andl(Register dst, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700848 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
849 EmitComplex(4, Operand(dst), imm);
850}
851
852
Ian Rogers2c8f6532011-09-02 17:16:34 -0700853void X86Assembler::orl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700854 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
855 EmitUint8(0x0B);
856 EmitOperand(dst, Operand(src));
857}
858
859
Ian Rogers2c8f6532011-09-02 17:16:34 -0700860void X86Assembler::orl(Register dst, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700861 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
862 EmitComplex(1, Operand(dst), imm);
863}
864
865
Ian Rogers2c8f6532011-09-02 17:16:34 -0700866void X86Assembler::xorl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700867 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
868 EmitUint8(0x33);
869 EmitOperand(dst, Operand(src));
870}
871
872
Ian Rogers2c8f6532011-09-02 17:16:34 -0700873void X86Assembler::addl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700874 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
875 EmitComplex(0, Operand(reg), imm);
876}
877
878
Ian Rogers2c8f6532011-09-02 17:16:34 -0700879void X86Assembler::addl(const Address& address, Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700880 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
881 EmitUint8(0x01);
882 EmitOperand(reg, address);
883}
884
885
Ian Rogers2c8f6532011-09-02 17:16:34 -0700886void X86Assembler::addl(const Address& address, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700887 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
888 EmitComplex(0, address, imm);
889}
890
891
Ian Rogers2c8f6532011-09-02 17:16:34 -0700892void X86Assembler::adcl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700893 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
894 EmitComplex(2, Operand(reg), imm);
895}
896
897
Ian Rogers2c8f6532011-09-02 17:16:34 -0700898void X86Assembler::adcl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700899 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
900 EmitUint8(0x13);
901 EmitOperand(dst, Operand(src));
902}
903
904
Ian Rogers2c8f6532011-09-02 17:16:34 -0700905void X86Assembler::adcl(Register dst, const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700906 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
907 EmitUint8(0x13);
908 EmitOperand(dst, address);
909}
910
911
Ian Rogers2c8f6532011-09-02 17:16:34 -0700912void X86Assembler::subl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700913 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
914 EmitUint8(0x2B);
915 EmitOperand(dst, Operand(src));
916}
917
918
Ian Rogers2c8f6532011-09-02 17:16:34 -0700919void X86Assembler::subl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700920 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
921 EmitComplex(5, Operand(reg), imm);
922}
923
924
Ian Rogers2c8f6532011-09-02 17:16:34 -0700925void X86Assembler::subl(Register reg, const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700926 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
927 EmitUint8(0x2B);
928 EmitOperand(reg, address);
929}
930
931
Ian Rogers2c8f6532011-09-02 17:16:34 -0700932void X86Assembler::cdq() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700933 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
934 EmitUint8(0x99);
935}
936
937
Ian Rogers2c8f6532011-09-02 17:16:34 -0700938void X86Assembler::idivl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700939 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
940 EmitUint8(0xF7);
941 EmitUint8(0xF8 | reg);
942}
943
944
Ian Rogers2c8f6532011-09-02 17:16:34 -0700945void X86Assembler::imull(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700946 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
947 EmitUint8(0x0F);
948 EmitUint8(0xAF);
949 EmitOperand(dst, Operand(src));
950}
951
952
Ian Rogers2c8f6532011-09-02 17:16:34 -0700953void X86Assembler::imull(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700954 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
955 EmitUint8(0x69);
956 EmitOperand(reg, Operand(reg));
957 EmitImmediate(imm);
958}
959
960
Ian Rogers2c8f6532011-09-02 17:16:34 -0700961void X86Assembler::imull(Register reg, const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700962 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
963 EmitUint8(0x0F);
964 EmitUint8(0xAF);
965 EmitOperand(reg, address);
966}
967
968
Ian Rogers2c8f6532011-09-02 17:16:34 -0700969void X86Assembler::imull(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700970 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
971 EmitUint8(0xF7);
972 EmitOperand(5, Operand(reg));
973}
974
975
Ian Rogers2c8f6532011-09-02 17:16:34 -0700976void X86Assembler::imull(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700977 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
978 EmitUint8(0xF7);
979 EmitOperand(5, address);
980}
981
982
Ian Rogers2c8f6532011-09-02 17:16:34 -0700983void X86Assembler::mull(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700984 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
985 EmitUint8(0xF7);
986 EmitOperand(4, Operand(reg));
987}
988
989
Ian Rogers2c8f6532011-09-02 17:16:34 -0700990void X86Assembler::mull(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700991 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
992 EmitUint8(0xF7);
993 EmitOperand(4, address);
994}
995
996
Ian Rogers2c8f6532011-09-02 17:16:34 -0700997void X86Assembler::sbbl(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700998 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
999 EmitUint8(0x1B);
1000 EmitOperand(dst, Operand(src));
1001}
1002
1003
Ian Rogers2c8f6532011-09-02 17:16:34 -07001004void X86Assembler::sbbl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001005 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1006 EmitComplex(3, Operand(reg), imm);
1007}
1008
1009
Ian Rogers2c8f6532011-09-02 17:16:34 -07001010void X86Assembler::sbbl(Register dst, const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001011 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1012 EmitUint8(0x1B);
1013 EmitOperand(dst, address);
1014}
1015
1016
Ian Rogers2c8f6532011-09-02 17:16:34 -07001017void X86Assembler::incl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001018 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1019 EmitUint8(0x40 + reg);
1020}
1021
1022
Ian Rogers2c8f6532011-09-02 17:16:34 -07001023void X86Assembler::incl(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001024 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1025 EmitUint8(0xFF);
1026 EmitOperand(0, address);
1027}
1028
1029
Ian Rogers2c8f6532011-09-02 17:16:34 -07001030void X86Assembler::decl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001031 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1032 EmitUint8(0x48 + reg);
1033}
1034
1035
Ian Rogers2c8f6532011-09-02 17:16:34 -07001036void X86Assembler::decl(const Address& address) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001037 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1038 EmitUint8(0xFF);
1039 EmitOperand(1, address);
1040}
1041
1042
Ian Rogers2c8f6532011-09-02 17:16:34 -07001043void X86Assembler::shll(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001044 EmitGenericShift(4, reg, imm);
1045}
1046
1047
Ian Rogers2c8f6532011-09-02 17:16:34 -07001048void X86Assembler::shll(Register operand, Register shifter) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001049 EmitGenericShift(4, operand, shifter);
1050}
1051
1052
Ian Rogers2c8f6532011-09-02 17:16:34 -07001053void X86Assembler::shrl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001054 EmitGenericShift(5, reg, imm);
1055}
1056
1057
Ian Rogers2c8f6532011-09-02 17:16:34 -07001058void X86Assembler::shrl(Register operand, Register shifter) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001059 EmitGenericShift(5, operand, shifter);
1060}
1061
1062
Ian Rogers2c8f6532011-09-02 17:16:34 -07001063void X86Assembler::sarl(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001064 EmitGenericShift(7, reg, imm);
1065}
1066
1067
Ian Rogers2c8f6532011-09-02 17:16:34 -07001068void X86Assembler::sarl(Register operand, Register shifter) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001069 EmitGenericShift(7, operand, shifter);
1070}
1071
1072
Ian Rogers2c8f6532011-09-02 17:16:34 -07001073void X86Assembler::shld(Register dst, Register src) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001074 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1075 EmitUint8(0x0F);
1076 EmitUint8(0xA5);
1077 EmitRegisterOperand(src, dst);
1078}
1079
1080
Ian Rogers2c8f6532011-09-02 17:16:34 -07001081void X86Assembler::negl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001082 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1083 EmitUint8(0xF7);
1084 EmitOperand(3, Operand(reg));
1085}
1086
1087
Ian Rogers2c8f6532011-09-02 17:16:34 -07001088void X86Assembler::notl(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001089 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1090 EmitUint8(0xF7);
1091 EmitUint8(0xD0 | reg);
1092}
1093
1094
Ian Rogers2c8f6532011-09-02 17:16:34 -07001095void X86Assembler::enter(const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001096 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1097 EmitUint8(0xC8);
1098 CHECK(imm.is_uint16());
1099 EmitUint8(imm.value() & 0xFF);
1100 EmitUint8((imm.value() >> 8) & 0xFF);
1101 EmitUint8(0x00);
1102}
1103
1104
Ian Rogers2c8f6532011-09-02 17:16:34 -07001105void X86Assembler::leave() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001106 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1107 EmitUint8(0xC9);
1108}
1109
1110
Ian Rogers2c8f6532011-09-02 17:16:34 -07001111void X86Assembler::ret() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001112 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1113 EmitUint8(0xC3);
1114}
1115
1116
Ian Rogers2c8f6532011-09-02 17:16:34 -07001117void X86Assembler::ret(const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001118 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1119 EmitUint8(0xC2);
1120 CHECK(imm.is_uint16());
1121 EmitUint8(imm.value() & 0xFF);
1122 EmitUint8((imm.value() >> 8) & 0xFF);
1123}
1124
1125
1126
Ian Rogers2c8f6532011-09-02 17:16:34 -07001127void X86Assembler::nop() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001128 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1129 EmitUint8(0x90);
1130}
1131
1132
Ian Rogers2c8f6532011-09-02 17:16:34 -07001133void X86Assembler::int3() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001134 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1135 EmitUint8(0xCC);
1136}
1137
1138
Ian Rogers2c8f6532011-09-02 17:16:34 -07001139void X86Assembler::hlt() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001140 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1141 EmitUint8(0xF4);
1142}
1143
1144
Ian Rogers2c8f6532011-09-02 17:16:34 -07001145void X86Assembler::j(Condition condition, Label* label) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001146 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1147 if (label->IsBound()) {
1148 static const int kShortSize = 2;
1149 static const int kLongSize = 6;
1150 int offset = label->Position() - buffer_.Size();
1151 CHECK_LE(offset, 0);
1152 if (IsInt(8, offset - kShortSize)) {
1153 EmitUint8(0x70 + condition);
1154 EmitUint8((offset - kShortSize) & 0xFF);
1155 } else {
1156 EmitUint8(0x0F);
1157 EmitUint8(0x80 + condition);
1158 EmitInt32(offset - kLongSize);
1159 }
1160 } else {
1161 EmitUint8(0x0F);
1162 EmitUint8(0x80 + condition);
1163 EmitLabelLink(label);
1164 }
1165}
1166
1167
Ian Rogers2c8f6532011-09-02 17:16:34 -07001168void X86Assembler::jmp(Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001169 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1170 EmitUint8(0xFF);
1171 EmitRegisterOperand(4, reg);
1172}
1173
1174
Ian Rogers2c8f6532011-09-02 17:16:34 -07001175void X86Assembler::jmp(Label* label) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001176 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1177 if (label->IsBound()) {
1178 static const int kShortSize = 2;
1179 static const int kLongSize = 5;
1180 int offset = label->Position() - buffer_.Size();
1181 CHECK_LE(offset, 0);
1182 if (IsInt(8, offset - kShortSize)) {
1183 EmitUint8(0xEB);
1184 EmitUint8((offset - kShortSize) & 0xFF);
1185 } else {
1186 EmitUint8(0xE9);
1187 EmitInt32(offset - kLongSize);
1188 }
1189 } else {
1190 EmitUint8(0xE9);
1191 EmitLabelLink(label);
1192 }
1193}
1194
1195
Ian Rogers2c8f6532011-09-02 17:16:34 -07001196X86Assembler* X86Assembler::lock() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001197 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1198 EmitUint8(0xF0);
Ian Rogers0d666d82011-08-14 16:03:46 -07001199 return this;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001200}
1201
1202
Ian Rogers2c8f6532011-09-02 17:16:34 -07001203void X86Assembler::cmpxchgl(const Address& address, Register reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001204 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1205 EmitUint8(0x0F);
1206 EmitUint8(0xB1);
1207 EmitOperand(reg, address);
1208}
1209
Elliott Hughes79ab9e32012-03-12 15:41:35 -07001210void X86Assembler::mfence() {
1211 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1212 EmitUint8(0x0F);
1213 EmitUint8(0xAE);
1214 EmitUint8(0xF0);
1215}
1216
Ian Rogers2c8f6532011-09-02 17:16:34 -07001217X86Assembler* X86Assembler::fs() {
Ian Rogersb033c752011-07-20 12:22:35 -07001218 // TODO: fs is a prefix and not an instruction
1219 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1220 EmitUint8(0x64);
Ian Rogers0d666d82011-08-14 16:03:46 -07001221 return this;
Ian Rogersb033c752011-07-20 12:22:35 -07001222}
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001223
Ian Rogers2c8f6532011-09-02 17:16:34 -07001224void X86Assembler::AddImmediate(Register reg, const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001225 int value = imm.value();
1226 if (value > 0) {
1227 if (value == 1) {
1228 incl(reg);
1229 } else if (value != 0) {
1230 addl(reg, imm);
1231 }
1232 } else if (value < 0) {
1233 value = -value;
1234 if (value == 1) {
1235 decl(reg);
1236 } else if (value != 0) {
1237 subl(reg, Immediate(value));
1238 }
1239 }
1240}
1241
1242
Ian Rogers2c8f6532011-09-02 17:16:34 -07001243void X86Assembler::LoadDoubleConstant(XmmRegister dst, double value) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001244 // TODO: Need to have a code constants table.
1245 int64_t constant = bit_cast<int64_t, double>(value);
1246 pushl(Immediate(High32Bits(constant)));
1247 pushl(Immediate(Low32Bits(constant)));
1248 movsd(dst, Address(ESP, 0));
1249 addl(ESP, Immediate(2 * kWordSize));
1250}
1251
1252
Ian Rogers2c8f6532011-09-02 17:16:34 -07001253void X86Assembler::FloatNegate(XmmRegister f) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001254 static const struct {
1255 uint32_t a;
1256 uint32_t b;
1257 uint32_t c;
1258 uint32_t d;
1259 } float_negate_constant __attribute__((aligned(16))) =
1260 { 0x80000000, 0x00000000, 0x80000000, 0x00000000 };
1261 xorps(f, Address::Absolute(reinterpret_cast<uword>(&float_negate_constant)));
1262}
1263
1264
Ian Rogers2c8f6532011-09-02 17:16:34 -07001265void X86Assembler::DoubleNegate(XmmRegister d) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001266 static const struct {
1267 uint64_t a;
1268 uint64_t b;
1269 } double_negate_constant __attribute__((aligned(16))) =
1270 {0x8000000000000000LL, 0x8000000000000000LL};
1271 xorpd(d, Address::Absolute(reinterpret_cast<uword>(&double_negate_constant)));
1272}
1273
1274
Ian Rogers2c8f6532011-09-02 17:16:34 -07001275void X86Assembler::DoubleAbs(XmmRegister reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001276 static const struct {
1277 uint64_t a;
1278 uint64_t b;
1279 } double_abs_constant __attribute__((aligned(16))) =
1280 {0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFFLL};
1281 andpd(reg, Address::Absolute(reinterpret_cast<uword>(&double_abs_constant)));
1282}
1283
1284
Ian Rogers2c8f6532011-09-02 17:16:34 -07001285void X86Assembler::Align(int alignment, int offset) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001286 CHECK(IsPowerOfTwo(alignment));
1287 // Emit nop instruction until the real position is aligned.
1288 while (((offset + buffer_.GetPosition()) & (alignment-1)) != 0) {
1289 nop();
1290 }
1291}
1292
1293
Ian Rogers2c8f6532011-09-02 17:16:34 -07001294void X86Assembler::Bind(Label* label) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001295 int bound = buffer_.Size();
1296 CHECK(!label->IsBound()); // Labels can only be bound once.
1297 while (label->IsLinked()) {
1298 int position = label->LinkPosition();
1299 int next = buffer_.Load<int32_t>(position);
1300 buffer_.Store<int32_t>(position, bound - (position + 4));
1301 label->position_ = next;
1302 }
1303 label->BindTo(bound);
1304}
1305
1306
Ian Rogers2c8f6532011-09-02 17:16:34 -07001307void X86Assembler::Stop(const char* message) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001308 // Emit the message address as immediate operand in the test rax instruction,
1309 // followed by the int3 instruction.
1310 // Execution can be resumed with the 'cont' command in gdb.
1311 testl(EAX, Immediate(reinterpret_cast<int32_t>(message)));
1312 int3();
1313}
1314
1315
Ian Rogers44fb0d02012-03-23 16:46:24 -07001316void X86Assembler::EmitOperand(int reg_or_opcode, const Operand& operand) {
1317 CHECK_GE(reg_or_opcode, 0);
1318 CHECK_LT(reg_or_opcode, 8);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001319 const int length = operand.length_;
1320 CHECK_GT(length, 0);
Ian Rogers44fb0d02012-03-23 16:46:24 -07001321 // Emit the ModRM byte updated with the given reg value.
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001322 CHECK_EQ(operand.encoding_[0] & 0x38, 0);
Ian Rogers44fb0d02012-03-23 16:46:24 -07001323 EmitUint8(operand.encoding_[0] + (reg_or_opcode << 3));
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001324 // Emit the rest of the encoded operand.
1325 for (int i = 1; i < length; i++) {
1326 EmitUint8(operand.encoding_[i]);
1327 }
1328}
1329
1330
Ian Rogers2c8f6532011-09-02 17:16:34 -07001331void X86Assembler::EmitImmediate(const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001332 EmitInt32(imm.value());
1333}
1334
1335
Ian Rogers44fb0d02012-03-23 16:46:24 -07001336void X86Assembler::EmitComplex(int reg_or_opcode,
Ian Rogers2c8f6532011-09-02 17:16:34 -07001337 const Operand& operand,
1338 const Immediate& immediate) {
Ian Rogers44fb0d02012-03-23 16:46:24 -07001339 CHECK_GE(reg_or_opcode, 0);
1340 CHECK_LT(reg_or_opcode, 8);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001341 if (immediate.is_int8()) {
1342 // Use sign-extended 8-bit immediate.
1343 EmitUint8(0x83);
Ian Rogers44fb0d02012-03-23 16:46:24 -07001344 EmitOperand(reg_or_opcode, operand);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001345 EmitUint8(immediate.value() & 0xFF);
1346 } else if (operand.IsRegister(EAX)) {
1347 // Use short form if the destination is eax.
Ian Rogers44fb0d02012-03-23 16:46:24 -07001348 EmitUint8(0x05 + (reg_or_opcode << 3));
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001349 EmitImmediate(immediate);
1350 } else {
1351 EmitUint8(0x81);
Ian Rogers44fb0d02012-03-23 16:46:24 -07001352 EmitOperand(reg_or_opcode, operand);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001353 EmitImmediate(immediate);
1354 }
1355}
1356
1357
Ian Rogers2c8f6532011-09-02 17:16:34 -07001358void X86Assembler::EmitLabel(Label* label, int instruction_size) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001359 if (label->IsBound()) {
1360 int offset = label->Position() - buffer_.Size();
1361 CHECK_LE(offset, 0);
1362 EmitInt32(offset - instruction_size);
1363 } else {
1364 EmitLabelLink(label);
1365 }
1366}
1367
1368
Ian Rogers2c8f6532011-09-02 17:16:34 -07001369void X86Assembler::EmitLabelLink(Label* label) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001370 CHECK(!label->IsBound());
1371 int position = buffer_.Size();
1372 EmitInt32(label->position_);
1373 label->LinkTo(position);
1374}
1375
1376
Ian Rogers44fb0d02012-03-23 16:46:24 -07001377void X86Assembler::EmitGenericShift(int reg_or_opcode,
Ian Rogers2c8f6532011-09-02 17:16:34 -07001378 Register reg,
1379 const Immediate& imm) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001380 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1381 CHECK(imm.is_int8());
1382 if (imm.value() == 1) {
1383 EmitUint8(0xD1);
Ian Rogers44fb0d02012-03-23 16:46:24 -07001384 EmitOperand(reg_or_opcode, Operand(reg));
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001385 } else {
1386 EmitUint8(0xC1);
Ian Rogers44fb0d02012-03-23 16:46:24 -07001387 EmitOperand(reg_or_opcode, Operand(reg));
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001388 EmitUint8(imm.value() & 0xFF);
1389 }
1390}
1391
1392
Ian Rogers44fb0d02012-03-23 16:46:24 -07001393void X86Assembler::EmitGenericShift(int reg_or_opcode,
Ian Rogers2c8f6532011-09-02 17:16:34 -07001394 Register operand,
1395 Register shifter) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001396 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
1397 CHECK_EQ(shifter, ECX);
1398 EmitUint8(0xD3);
Ian Rogers44fb0d02012-03-23 16:46:24 -07001399 EmitOperand(reg_or_opcode, Operand(operand));
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -07001400}
1401
Ian Rogers2c8f6532011-09-02 17:16:34 -07001402void X86Assembler::BuildFrame(size_t frame_size, ManagedRegister method_reg,
Ian Rogersb5d09b22012-03-06 22:14:17 -08001403 const std::vector<ManagedRegister>& spill_regs,
1404 const std::vector<ManagedRegister>& entry_spills) {
Elliott Hughes06b37d92011-10-16 11:51:29 -07001405 CHECK_ALIGNED(frame_size, kStackAlignment);
Ian Rogers0d666d82011-08-14 16:03:46 -07001406 CHECK_EQ(0u, spill_regs.size()); // no spilled regs on x86
Ian Rogersb033c752011-07-20 12:22:35 -07001407 // return address then method on stack
Ian Rogers0d666d82011-08-14 16:03:46 -07001408 addl(ESP, Immediate(-frame_size + kPointerSize /*method*/ +
1409 kPointerSize /*return address*/));
Ian Rogers2c8f6532011-09-02 17:16:34 -07001410 pushl(method_reg.AsX86().AsCpuRegister());
Ian Rogersb5d09b22012-03-06 22:14:17 -08001411 for (size_t i = 0; i < entry_spills.size(); ++i) {
1412 movl(Address(ESP, frame_size + kPointerSize + (i * kPointerSize)),
1413 entry_spills.at(i).AsX86().AsCpuRegister());
1414 }
Ian Rogersb033c752011-07-20 12:22:35 -07001415}
1416
Ian Rogers2c8f6532011-09-02 17:16:34 -07001417void X86Assembler::RemoveFrame(size_t frame_size,
Ian Rogers0d666d82011-08-14 16:03:46 -07001418 const std::vector<ManagedRegister>& spill_regs) {
Elliott Hughes06b37d92011-10-16 11:51:29 -07001419 CHECK_ALIGNED(frame_size, kStackAlignment);
Ian Rogers0d666d82011-08-14 16:03:46 -07001420 CHECK_EQ(0u, spill_regs.size()); // no spilled regs on x86
1421 addl(ESP, Immediate(frame_size - kPointerSize));
Ian Rogersb033c752011-07-20 12:22:35 -07001422 ret();
1423}
1424
Ian Rogers2c8f6532011-09-02 17:16:34 -07001425void X86Assembler::IncreaseFrameSize(size_t adjust) {
Elliott Hughes06b37d92011-10-16 11:51:29 -07001426 CHECK_ALIGNED(adjust, kStackAlignment);
Ian Rogersb033c752011-07-20 12:22:35 -07001427 addl(ESP, Immediate(-adjust));
1428}
1429
Ian Rogers2c8f6532011-09-02 17:16:34 -07001430void X86Assembler::DecreaseFrameSize(size_t adjust) {
Elliott Hughes06b37d92011-10-16 11:51:29 -07001431 CHECK_ALIGNED(adjust, kStackAlignment);
Ian Rogersb033c752011-07-20 12:22:35 -07001432 addl(ESP, Immediate(adjust));
1433}
1434
Ian Rogers2c8f6532011-09-02 17:16:34 -07001435void X86Assembler::Store(FrameOffset offs, ManagedRegister msrc, size_t size) {
1436 X86ManagedRegister src = msrc.AsX86();
Ian Rogers45a76cb2011-07-21 22:00:15 -07001437 if (src.IsNoRegister()) {
1438 CHECK_EQ(0u, size);
1439 } else if (src.IsCpuRegister()) {
Ian Rogersb033c752011-07-20 12:22:35 -07001440 CHECK_EQ(4u, size);
1441 movl(Address(ESP, offs), src.AsCpuRegister());
Ian Rogers9b269d22011-09-04 14:06:05 -07001442 } else if (src.IsRegisterPair()) {
1443 CHECK_EQ(8u, size);
1444 movl(Address(ESP, offs), src.AsRegisterPairLow());
1445 movl(Address(ESP, FrameOffset(offs.Int32Value()+4)),
1446 src.AsRegisterPairHigh());
Ian Rogers45a76cb2011-07-21 22:00:15 -07001447 } else if (src.IsX87Register()) {
1448 if (size == 4) {
1449 fstps(Address(ESP, offs));
1450 } else {
1451 fstpl(Address(ESP, offs));
1452 }
1453 } else {
1454 CHECK(src.IsXmmRegister());
Ian Rogersb033c752011-07-20 12:22:35 -07001455 if (size == 4) {
1456 movss(Address(ESP, offs), src.AsXmmRegister());
1457 } else {
1458 movsd(Address(ESP, offs), src.AsXmmRegister());
1459 }
1460 }
1461}
1462
Ian Rogers2c8f6532011-09-02 17:16:34 -07001463void X86Assembler::StoreRef(FrameOffset dest, ManagedRegister msrc) {
1464 X86ManagedRegister src = msrc.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001465 CHECK(src.IsCpuRegister());
1466 movl(Address(ESP, dest), src.AsCpuRegister());
1467}
1468
Ian Rogers2c8f6532011-09-02 17:16:34 -07001469void X86Assembler::StoreRawPtr(FrameOffset dest, ManagedRegister msrc) {
1470 X86ManagedRegister src = msrc.AsX86();
Ian Rogersdf20fe02011-07-20 20:34:16 -07001471 CHECK(src.IsCpuRegister());
1472 movl(Address(ESP, dest), src.AsCpuRegister());
1473}
1474
Ian Rogers2c8f6532011-09-02 17:16:34 -07001475void X86Assembler::StoreImmediateToFrame(FrameOffset dest, uint32_t imm,
1476 ManagedRegister) {
Ian Rogersb033c752011-07-20 12:22:35 -07001477 movl(Address(ESP, dest), Immediate(imm));
1478}
1479
Ian Rogers2c8f6532011-09-02 17:16:34 -07001480void X86Assembler::StoreImmediateToThread(ThreadOffset dest, uint32_t imm,
1481 ManagedRegister) {
Ian Rogers0d666d82011-08-14 16:03:46 -07001482 fs()->movl(Address::Absolute(dest), Immediate(imm));
Ian Rogersb033c752011-07-20 12:22:35 -07001483}
1484
Ian Rogers2c8f6532011-09-02 17:16:34 -07001485void X86Assembler::StoreStackOffsetToThread(ThreadOffset thr_offs,
1486 FrameOffset fr_offs,
1487 ManagedRegister mscratch) {
1488 X86ManagedRegister scratch = mscratch.AsX86();
1489 CHECK(scratch.IsCpuRegister());
1490 leal(scratch.AsCpuRegister(), Address(ESP, fr_offs));
1491 fs()->movl(Address::Absolute(thr_offs), scratch.AsCpuRegister());
1492}
1493
1494void X86Assembler::StoreStackPointerToThread(ThreadOffset thr_offs) {
1495 fs()->movl(Address::Absolute(thr_offs), ESP);
1496}
1497
Ian Rogersbdb03912011-09-14 00:55:44 -07001498void X86Assembler::StoreLabelToThread(ThreadOffset thr_offs, Label* lbl) {
1499 fs()->movl(Address::Absolute(thr_offs), lbl);
1500}
1501
Elliott Hughes1bac54f2012-03-16 12:48:31 -07001502void X86Assembler::StoreSpanning(FrameOffset /*dst*/, ManagedRegister /*src*/,
1503 FrameOffset /*in_off*/, ManagedRegister /*scratch*/) {
Ian Rogers2c8f6532011-09-02 17:16:34 -07001504 UNIMPLEMENTED(FATAL); // this case only currently exists for ARM
1505}
1506
1507void X86Assembler::Load(ManagedRegister mdest, FrameOffset src, size_t size) {
1508 X86ManagedRegister dest = mdest.AsX86();
Ian Rogers45a76cb2011-07-21 22:00:15 -07001509 if (dest.IsNoRegister()) {
1510 CHECK_EQ(0u, size);
1511 } else if (dest.IsCpuRegister()) {
Ian Rogersb033c752011-07-20 12:22:35 -07001512 CHECK_EQ(4u, size);
1513 movl(dest.AsCpuRegister(), Address(ESP, src));
Ian Rogers9b269d22011-09-04 14:06:05 -07001514 } else if (dest.IsRegisterPair()) {
1515 CHECK_EQ(8u, size);
1516 movl(dest.AsRegisterPairLow(), Address(ESP, src));
1517 movl(dest.AsRegisterPairHigh(), Address(ESP, FrameOffset(src.Int32Value()+4)));
Ian Rogers45a76cb2011-07-21 22:00:15 -07001518 } else if (dest.IsX87Register()) {
1519 if (size == 4) {
1520 flds(Address(ESP, src));
1521 } else {
1522 fldl(Address(ESP, src));
1523 }
Ian Rogersb033c752011-07-20 12:22:35 -07001524 } else {
Ian Rogers45a76cb2011-07-21 22:00:15 -07001525 CHECK(dest.IsXmmRegister());
1526 if (size == 4) {
1527 movss(dest.AsXmmRegister(), Address(ESP, src));
1528 } else {
1529 movsd(dest.AsXmmRegister(), Address(ESP, src));
1530 }
Ian Rogersb033c752011-07-20 12:22:35 -07001531 }
1532}
1533
Ian Rogers5a7a74a2011-09-26 16:32:29 -07001534void X86Assembler::Load(ManagedRegister mdest, ThreadOffset src, size_t size) {
1535 X86ManagedRegister dest = mdest.AsX86();
1536 if (dest.IsNoRegister()) {
1537 CHECK_EQ(0u, size);
1538 } else if (dest.IsCpuRegister()) {
1539 CHECK_EQ(4u, size);
1540 fs()->movl(dest.AsCpuRegister(), Address::Absolute(src));
1541 } else if (dest.IsRegisterPair()) {
1542 CHECK_EQ(8u, size);
1543 fs()->movl(dest.AsRegisterPairLow(), Address::Absolute(src));
1544 fs()->movl(dest.AsRegisterPairHigh(), Address::Absolute(ThreadOffset(src.Int32Value()+4)));
1545 } else if (dest.IsX87Register()) {
1546 if (size == 4) {
1547 fs()->flds(Address::Absolute(src));
1548 } else {
1549 fs()->fldl(Address::Absolute(src));
1550 }
1551 } else {
1552 CHECK(dest.IsXmmRegister());
1553 if (size == 4) {
1554 fs()->movss(dest.AsXmmRegister(), Address::Absolute(src));
1555 } else {
1556 fs()->movsd(dest.AsXmmRegister(), Address::Absolute(src));
1557 }
1558 }
1559}
1560
Ian Rogers2c8f6532011-09-02 17:16:34 -07001561void X86Assembler::LoadRef(ManagedRegister mdest, FrameOffset src) {
1562 X86ManagedRegister dest = mdest.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001563 CHECK(dest.IsCpuRegister());
1564 movl(dest.AsCpuRegister(), Address(ESP, src));
1565}
1566
Ian Rogers2c8f6532011-09-02 17:16:34 -07001567void X86Assembler::LoadRef(ManagedRegister mdest, ManagedRegister base,
1568 MemberOffset offs) {
1569 X86ManagedRegister dest = mdest.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001570 CHECK(dest.IsCpuRegister() && dest.IsCpuRegister());
Ian Rogers2c8f6532011-09-02 17:16:34 -07001571 movl(dest.AsCpuRegister(), Address(base.AsX86().AsCpuRegister(), offs));
Ian Rogersb033c752011-07-20 12:22:35 -07001572}
1573
Ian Rogers2c8f6532011-09-02 17:16:34 -07001574void X86Assembler::LoadRawPtr(ManagedRegister mdest, ManagedRegister base,
1575 Offset offs) {
1576 X86ManagedRegister dest = mdest.AsX86();
Ian Rogersa04d3972011-08-17 11:33:44 -07001577 CHECK(dest.IsCpuRegister() && dest.IsCpuRegister());
Ian Rogers2c8f6532011-09-02 17:16:34 -07001578 movl(dest.AsCpuRegister(), Address(base.AsX86().AsCpuRegister(), offs));
Ian Rogersa04d3972011-08-17 11:33:44 -07001579}
1580
Ian Rogers2c8f6532011-09-02 17:16:34 -07001581void X86Assembler::LoadRawPtrFromThread(ManagedRegister mdest,
1582 ThreadOffset offs) {
1583 X86ManagedRegister dest = mdest.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001584 CHECK(dest.IsCpuRegister());
Ian Rogers0d666d82011-08-14 16:03:46 -07001585 fs()->movl(dest.AsCpuRegister(), Address::Absolute(offs));
Ian Rogersb033c752011-07-20 12:22:35 -07001586}
1587
Ian Rogersb5d09b22012-03-06 22:14:17 -08001588void X86Assembler::Move(ManagedRegister mdest, ManagedRegister msrc, size_t size) {
Ian Rogers2c8f6532011-09-02 17:16:34 -07001589 X86ManagedRegister dest = mdest.AsX86();
1590 X86ManagedRegister src = msrc.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001591 if (!dest.Equals(src)) {
1592 if (dest.IsCpuRegister() && src.IsCpuRegister()) {
1593 movl(dest.AsCpuRegister(), src.AsCpuRegister());
Ian Rogersb5d09b22012-03-06 22:14:17 -08001594 } else if (src.IsX87Register() && dest.IsXmmRegister()) {
1595 // Pass via stack and pop X87 register
1596 subl(ESP, Immediate(16));
1597 if (size == 4) {
1598 CHECK_EQ(src.AsX87Register(), ST0);
1599 fstps(Address(ESP, 0));
1600 movss(dest.AsXmmRegister(), Address(ESP, 0));
1601 } else {
1602 CHECK_EQ(src.AsX87Register(), ST0);
1603 fstpl(Address(ESP, 0));
1604 movsd(dest.AsXmmRegister(), Address(ESP, 0));
1605 }
1606 addl(ESP, Immediate(16));
Ian Rogersb033c752011-07-20 12:22:35 -07001607 } else {
1608 // TODO: x87, SSE
Ian Rogers2c8f6532011-09-02 17:16:34 -07001609 UNIMPLEMENTED(FATAL) << ": Move " << dest << ", " << src;
Ian Rogersb033c752011-07-20 12:22:35 -07001610 }
1611 }
1612}
1613
Ian Rogers2c8f6532011-09-02 17:16:34 -07001614void X86Assembler::CopyRef(FrameOffset dest, FrameOffset src,
1615 ManagedRegister mscratch) {
1616 X86ManagedRegister scratch = mscratch.AsX86();
1617 CHECK(scratch.IsCpuRegister());
1618 movl(scratch.AsCpuRegister(), Address(ESP, src));
1619 movl(Address(ESP, dest), scratch.AsCpuRegister());
1620}
1621
1622void X86Assembler::CopyRawPtrFromThread(FrameOffset fr_offs,
1623 ThreadOffset thr_offs,
1624 ManagedRegister mscratch) {
1625 X86ManagedRegister scratch = mscratch.AsX86();
1626 CHECK(scratch.IsCpuRegister());
1627 fs()->movl(scratch.AsCpuRegister(), Address::Absolute(thr_offs));
1628 Store(fr_offs, scratch, 4);
1629}
1630
1631void X86Assembler::CopyRawPtrToThread(ThreadOffset thr_offs,
1632 FrameOffset fr_offs,
1633 ManagedRegister mscratch) {
1634 X86ManagedRegister scratch = mscratch.AsX86();
1635 CHECK(scratch.IsCpuRegister());
1636 Load(scratch, fr_offs, 4);
1637 fs()->movl(Address::Absolute(thr_offs), scratch.AsCpuRegister());
1638}
1639
1640void X86Assembler::Copy(FrameOffset dest, FrameOffset src,
1641 ManagedRegister mscratch,
1642 size_t size) {
1643 X86ManagedRegister scratch = mscratch.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001644 if (scratch.IsCpuRegister() && size == 8) {
1645 Load(scratch, src, 4);
1646 Store(dest, scratch, 4);
1647 Load(scratch, FrameOffset(src.Int32Value() + 4), 4);
1648 Store(FrameOffset(dest.Int32Value() + 4), scratch, 4);
1649 } else {
1650 Load(scratch, src, size);
1651 Store(dest, scratch, size);
1652 }
1653}
1654
Elliott Hughes1bac54f2012-03-16 12:48:31 -07001655void X86Assembler::Copy(FrameOffset /*dst*/, ManagedRegister /*src_base*/, Offset /*src_offset*/,
1656 ManagedRegister /*scratch*/, size_t /*size*/) {
Ian Rogersdc51b792011-09-22 20:41:37 -07001657 UNIMPLEMENTED(FATAL);
1658}
1659
Ian Rogers5a7a74a2011-09-26 16:32:29 -07001660void X86Assembler::Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src,
1661 ManagedRegister scratch, size_t size) {
1662 CHECK(scratch.IsNoRegister());
1663 CHECK_EQ(size, 4u);
1664 pushl(Address(ESP, src));
1665 popl(Address(dest_base.AsX86().AsCpuRegister(), dest_offset));
1666}
1667
Ian Rogersdc51b792011-09-22 20:41:37 -07001668void X86Assembler::Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset,
1669 ManagedRegister mscratch, size_t size) {
1670 Register scratch = mscratch.AsX86().AsCpuRegister();
1671 CHECK_EQ(size, 4u);
1672 movl(scratch, Address(ESP, src_base));
1673 movl(scratch, Address(scratch, src_offset));
1674 movl(Address(ESP, dest), scratch);
1675}
1676
Ian Rogers5a7a74a2011-09-26 16:32:29 -07001677void X86Assembler::Copy(ManagedRegister dest, Offset dest_offset,
1678 ManagedRegister src, Offset src_offset,
1679 ManagedRegister scratch, size_t size) {
Ian Rogersdc51b792011-09-22 20:41:37 -07001680 CHECK_EQ(size, 4u);
Ian Rogers5a7a74a2011-09-26 16:32:29 -07001681 CHECK(scratch.IsNoRegister());
1682 pushl(Address(src.AsX86().AsCpuRegister(), src_offset));
1683 popl(Address(dest.AsX86().AsCpuRegister(), dest_offset));
1684}
1685
1686void X86Assembler::Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset,
1687 ManagedRegister mscratch, size_t size) {
1688 Register scratch = mscratch.AsX86().AsCpuRegister();
1689 CHECK_EQ(size, 4u);
1690 CHECK_EQ(dest.Int32Value(), src.Int32Value());
1691 movl(scratch, Address(ESP, src));
1692 pushl(Address(scratch, src_offset));
Ian Rogersdc51b792011-09-22 20:41:37 -07001693 popl(Address(scratch, dest_offset));
1694}
1695
Ian Rogerse5de95b2011-09-18 20:31:38 -07001696void X86Assembler::MemoryBarrier(ManagedRegister) {
1697#if ANDROID_SMP != 0
Elliott Hughes79ab9e32012-03-12 15:41:35 -07001698 mfence();
Ian Rogerse5de95b2011-09-18 20:31:38 -07001699#endif
1700}
1701
Ian Rogers2c8f6532011-09-02 17:16:34 -07001702void X86Assembler::CreateSirtEntry(ManagedRegister mout_reg,
1703 FrameOffset sirt_offset,
1704 ManagedRegister min_reg, bool null_allowed) {
1705 X86ManagedRegister out_reg = mout_reg.AsX86();
1706 X86ManagedRegister in_reg = min_reg.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001707 CHECK(in_reg.IsCpuRegister());
1708 CHECK(out_reg.IsCpuRegister());
Ian Rogers408f79a2011-08-23 18:22:33 -07001709 VerifyObject(in_reg, null_allowed);
Ian Rogersb033c752011-07-20 12:22:35 -07001710 if (null_allowed) {
1711 Label null_arg;
1712 if (!out_reg.Equals(in_reg)) {
1713 xorl(out_reg.AsCpuRegister(), out_reg.AsCpuRegister());
1714 }
1715 testl(in_reg.AsCpuRegister(), in_reg.AsCpuRegister());
Elliott Hughes18c07532011-08-18 15:50:51 -07001716 j(kZero, &null_arg);
Ian Rogers408f79a2011-08-23 18:22:33 -07001717 leal(out_reg.AsCpuRegister(), Address(ESP, sirt_offset));
Ian Rogersb033c752011-07-20 12:22:35 -07001718 Bind(&null_arg);
1719 } else {
Ian Rogers408f79a2011-08-23 18:22:33 -07001720 leal(out_reg.AsCpuRegister(), Address(ESP, sirt_offset));
Ian Rogersb033c752011-07-20 12:22:35 -07001721 }
1722}
1723
Ian Rogers2c8f6532011-09-02 17:16:34 -07001724void X86Assembler::CreateSirtEntry(FrameOffset out_off,
1725 FrameOffset sirt_offset,
1726 ManagedRegister mscratch,
1727 bool null_allowed) {
1728 X86ManagedRegister scratch = mscratch.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001729 CHECK(scratch.IsCpuRegister());
1730 if (null_allowed) {
1731 Label null_arg;
Ian Rogers408f79a2011-08-23 18:22:33 -07001732 movl(scratch.AsCpuRegister(), Address(ESP, sirt_offset));
Ian Rogersb033c752011-07-20 12:22:35 -07001733 testl(scratch.AsCpuRegister(), scratch.AsCpuRegister());
Elliott Hughes18c07532011-08-18 15:50:51 -07001734 j(kZero, &null_arg);
Ian Rogers408f79a2011-08-23 18:22:33 -07001735 leal(scratch.AsCpuRegister(), Address(ESP, sirt_offset));
Ian Rogersb033c752011-07-20 12:22:35 -07001736 Bind(&null_arg);
1737 } else {
Ian Rogers408f79a2011-08-23 18:22:33 -07001738 leal(scratch.AsCpuRegister(), Address(ESP, sirt_offset));
Ian Rogersb033c752011-07-20 12:22:35 -07001739 }
1740 Store(out_off, scratch, 4);
1741}
1742
Ian Rogers408f79a2011-08-23 18:22:33 -07001743// Given a SIRT entry, load the associated reference.
Ian Rogers2c8f6532011-09-02 17:16:34 -07001744void X86Assembler::LoadReferenceFromSirt(ManagedRegister mout_reg,
1745 ManagedRegister min_reg) {
1746 X86ManagedRegister out_reg = mout_reg.AsX86();
1747 X86ManagedRegister in_reg = min_reg.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001748 CHECK(out_reg.IsCpuRegister());
1749 CHECK(in_reg.IsCpuRegister());
1750 Label null_arg;
1751 if (!out_reg.Equals(in_reg)) {
1752 xorl(out_reg.AsCpuRegister(), out_reg.AsCpuRegister());
1753 }
1754 testl(in_reg.AsCpuRegister(), in_reg.AsCpuRegister());
Elliott Hughes18c07532011-08-18 15:50:51 -07001755 j(kZero, &null_arg);
Ian Rogersb033c752011-07-20 12:22:35 -07001756 movl(out_reg.AsCpuRegister(), Address(in_reg.AsCpuRegister(), 0));
1757 Bind(&null_arg);
1758}
1759
Elliott Hughes1bac54f2012-03-16 12:48:31 -07001760void X86Assembler::VerifyObject(ManagedRegister /*src*/, bool /*could_be_null*/) {
Ian Rogersb033c752011-07-20 12:22:35 -07001761 // TODO: not validating references
1762}
1763
Elliott Hughes1bac54f2012-03-16 12:48:31 -07001764void X86Assembler::VerifyObject(FrameOffset /*src*/, bool /*could_be_null*/) {
Ian Rogersb033c752011-07-20 12:22:35 -07001765 // TODO: not validating references
1766}
1767
Ian Rogers2c8f6532011-09-02 17:16:34 -07001768void X86Assembler::Call(ManagedRegister mbase, Offset offset, ManagedRegister) {
1769 X86ManagedRegister base = mbase.AsX86();
Ian Rogersb033c752011-07-20 12:22:35 -07001770 CHECK(base.IsCpuRegister());
Ian Rogersdf20fe02011-07-20 20:34:16 -07001771 call(Address(base.AsCpuRegister(), offset.Int32Value()));
Ian Rogersb033c752011-07-20 12:22:35 -07001772 // TODO: place reference map on call
1773}
1774
Ian Rogers67375ac2011-09-14 00:55:44 -07001775void X86Assembler::Call(FrameOffset base, Offset offset, ManagedRegister mscratch) {
1776 Register scratch = mscratch.AsX86().AsCpuRegister();
1777 movl(scratch, Address(ESP, base));
1778 call(Address(scratch, offset));
Carl Shapiroe2d373e2011-07-25 15:20:06 -07001779}
1780
Elliott Hughes1bac54f2012-03-16 12:48:31 -07001781void X86Assembler::Call(ThreadOffset offset, ManagedRegister /*mscratch*/) {
Ian Rogersbdb03912011-09-14 00:55:44 -07001782 fs()->call(Address::Absolute(offset));
Shih-wei Liao668512a2011-09-01 14:18:34 -07001783}
1784
Ian Rogers2c8f6532011-09-02 17:16:34 -07001785void X86Assembler::GetCurrentThread(ManagedRegister tr) {
1786 fs()->movl(tr.AsX86().AsCpuRegister(),
1787 Address::Absolute(Thread::SelfOffset()));
Shih-wei Liao668512a2011-09-01 14:18:34 -07001788}
1789
Ian Rogers2c8f6532011-09-02 17:16:34 -07001790void X86Assembler::GetCurrentThread(FrameOffset offset,
1791 ManagedRegister mscratch) {
1792 X86ManagedRegister scratch = mscratch.AsX86();
Shih-wei Liao668512a2011-09-01 14:18:34 -07001793 fs()->movl(scratch.AsCpuRegister(), Address::Absolute(Thread::SelfOffset()));
1794 movl(Address(ESP, offset), scratch.AsCpuRegister());
1795}
1796
Elliott Hughes1bac54f2012-03-16 12:48:31 -07001797void X86Assembler::SuspendPoll(ManagedRegister /*scratch*/,
Ian Rogers2c8f6532011-09-02 17:16:34 -07001798 ManagedRegister return_reg,
1799 FrameOffset return_save_location,
1800 size_t return_size) {
1801 X86SuspendCountSlowPath* slow =
1802 new X86SuspendCountSlowPath(return_reg.AsX86(), return_save_location,
1803 return_size);
Ian Rogers45a76cb2011-07-21 22:00:15 -07001804 buffer_.EnqueueSlowPath(slow);
Ian Rogers0d666d82011-08-14 16:03:46 -07001805 fs()->cmpl(Address::Absolute(Thread::SuspendCountOffset()), Immediate(0));
Elliott Hughes18c07532011-08-18 15:50:51 -07001806 j(kNotEqual, slow->Entry());
Ian Rogers45a76cb2011-07-21 22:00:15 -07001807 Bind(slow->Continuation());
1808}
Ian Rogers0d666d82011-08-14 16:03:46 -07001809
Ian Rogers2c8f6532011-09-02 17:16:34 -07001810void X86SuspendCountSlowPath::Emit(Assembler *sasm) {
1811 X86Assembler* sp_asm = down_cast<X86Assembler*>(sasm);
Ian Rogers0d666d82011-08-14 16:03:46 -07001812#define __ sp_asm->
1813 __ Bind(&entry_);
Ian Rogers45a76cb2011-07-21 22:00:15 -07001814 // Save return value
Ian Rogers0d666d82011-08-14 16:03:46 -07001815 __ Store(return_save_location_, return_register_, return_size_);
Ian Rogerse5de95b2011-09-18 20:31:38 -07001816 // Pass Thread::Current as argument
1817 __ fs()->pushl(Address::Absolute(Thread::SelfOffset()));
1818 __ fs()->call(Address::Absolute(OFFSETOF_MEMBER(Thread, pCheckSuspendFromCode)));
Ian Rogers45a76cb2011-07-21 22:00:15 -07001819 // Release argument
Ian Rogers0d666d82011-08-14 16:03:46 -07001820 __ addl(ESP, Immediate(kPointerSize));
Ian Rogers45a76cb2011-07-21 22:00:15 -07001821 // Reload return value
Ian Rogers0d666d82011-08-14 16:03:46 -07001822 __ Load(return_register_, return_save_location_, return_size_);
1823 __ jmp(&continuation_);
1824#undef __
Ian Rogers45a76cb2011-07-21 22:00:15 -07001825}
1826
Elliott Hughes1bac54f2012-03-16 12:48:31 -07001827void X86Assembler::ExceptionPoll(ManagedRegister /*scratch*/) {
Ian Rogers2c8f6532011-09-02 17:16:34 -07001828 X86ExceptionSlowPath* slow = new X86ExceptionSlowPath();
Ian Rogers45a76cb2011-07-21 22:00:15 -07001829 buffer_.EnqueueSlowPath(slow);
Ian Rogers0d666d82011-08-14 16:03:46 -07001830 fs()->cmpl(Address::Absolute(Thread::ExceptionOffset()), Immediate(0));
Elliott Hughes18c07532011-08-18 15:50:51 -07001831 j(kNotEqual, slow->Entry());
Ian Rogers45a76cb2011-07-21 22:00:15 -07001832}
Ian Rogers0d666d82011-08-14 16:03:46 -07001833
Ian Rogers2c8f6532011-09-02 17:16:34 -07001834void X86ExceptionSlowPath::Emit(Assembler *sasm) {
1835 X86Assembler* sp_asm = down_cast<X86Assembler*>(sasm);
Ian Rogers0d666d82011-08-14 16:03:46 -07001836#define __ sp_asm->
1837 __ Bind(&entry_);
Elliott Hughes20cde902011-10-04 17:37:27 -07001838 // Note: the return value is dead
Ian Rogers67375ac2011-09-14 00:55:44 -07001839 // Pass exception as argument in EAX
1840 __ fs()->movl(EAX, Address::Absolute(Thread::ExceptionOffset()));
1841 __ fs()->call(Address::Absolute(OFFSETOF_MEMBER(Thread, pDeliverException)));
1842 // this call should never return
1843 __ int3();
Ian Rogers0d666d82011-08-14 16:03:46 -07001844#undef __
Ian Rogers45a76cb2011-07-21 22:00:15 -07001845}
1846
Ian Rogers2c8f6532011-09-02 17:16:34 -07001847} // namespace x86
Ian Rogersb033c752011-07-20 12:22:35 -07001848} // namespace art