Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 3 | #include "assembler_x86.h" |
| 4 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 5 | #include "casts.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 6 | #include "memory_region.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 7 | #include "thread.h" |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 8 | |
Carl Shapiro | 6b6b5f0 | 2011-06-21 15:05:09 -0700 | [diff] [blame] | 9 | namespace art { |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 10 | namespace x86 { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 11 | |
| 12 | class DirectCallRelocation : public AssemblerFixup { |
| 13 | public: |
| 14 | void Process(const MemoryRegion& region, int position) { |
| 15 | // Direct calls are relative to the following instruction on x86. |
| 16 | int32_t pointer = region.Load<int32_t>(position); |
| 17 | int32_t start = reinterpret_cast<int32_t>(region.start()); |
| 18 | int32_t delta = start + position + sizeof(int32_t); |
| 19 | region.Store<int32_t>(position, pointer - delta); |
| 20 | } |
| 21 | }; |
| 22 | |
Elliott Hughes | 1f359b0 | 2011-07-17 14:27:17 -0700 | [diff] [blame] | 23 | static const char* kRegisterNames[] = { |
| 24 | "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", |
| 25 | }; |
| 26 | std::ostream& operator<<(std::ostream& os, const Register& rhs) { |
| 27 | if (rhs >= EAX && rhs <= EDI) { |
| 28 | os << kRegisterNames[rhs]; |
| 29 | } else { |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 30 | os << "Register[" << static_cast<int>(rhs) << "]"; |
Elliott Hughes | 1f359b0 | 2011-07-17 14:27:17 -0700 | [diff] [blame] | 31 | } |
| 32 | return os; |
| 33 | } |
| 34 | |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 35 | std::ostream& operator<<(std::ostream& os, const XmmRegister& reg) { |
| 36 | return os << "XMM" << static_cast<int>(reg); |
| 37 | } |
| 38 | |
| 39 | std::ostream& operator<<(std::ostream& os, const X87Register& reg) { |
| 40 | return os << "ST" << static_cast<int>(reg); |
| 41 | } |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 42 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 43 | void X86Assembler::InitializeMemoryWithBreakpoints(byte* data, size_t length) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 44 | memset(reinterpret_cast<void*>(data), Instr::kBreakPointInstruction, length); |
| 45 | } |
| 46 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 47 | void X86Assembler::call(Register reg) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 48 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 49 | EmitUint8(0xFF); |
| 50 | EmitRegisterOperand(2, reg); |
| 51 | } |
| 52 | |
| 53 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 54 | void X86Assembler::call(const Address& address) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 55 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 56 | EmitUint8(0xFF); |
| 57 | EmitOperand(2, address); |
| 58 | } |
| 59 | |
| 60 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 61 | void X86Assembler::call(Label* label) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 62 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 63 | EmitUint8(0xE8); |
| 64 | static const int kSize = 5; |
| 65 | EmitLabel(label, kSize); |
| 66 | } |
| 67 | |
| 68 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 69 | void X86Assembler::pushl(Register reg) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 70 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 71 | EmitUint8(0x50 + reg); |
| 72 | } |
| 73 | |
| 74 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 75 | void X86Assembler::pushl(const Address& address) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 76 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 77 | EmitUint8(0xFF); |
| 78 | EmitOperand(6, address); |
| 79 | } |
| 80 | |
| 81 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 82 | void X86Assembler::pushl(const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 83 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 84 | EmitUint8(0x68); |
| 85 | EmitImmediate(imm); |
| 86 | } |
| 87 | |
| 88 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 89 | void X86Assembler::popl(Register reg) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 90 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 91 | EmitUint8(0x58 + reg); |
| 92 | } |
| 93 | |
| 94 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 95 | void X86Assembler::popl(const Address& address) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 96 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 97 | EmitUint8(0x8F); |
| 98 | EmitOperand(0, address); |
| 99 | } |
| 100 | |
| 101 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 102 | void X86Assembler::movl(Register dst, const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 103 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 104 | EmitUint8(0xB8 + dst); |
| 105 | EmitImmediate(imm); |
| 106 | } |
| 107 | |
| 108 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 109 | void X86Assembler::movl(Register dst, Register src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 110 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 111 | EmitUint8(0x89); |
| 112 | EmitRegisterOperand(src, dst); |
| 113 | } |
| 114 | |
| 115 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 116 | void X86Assembler::movl(Register dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 117 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 118 | EmitUint8(0x8B); |
| 119 | EmitOperand(dst, src); |
| 120 | } |
| 121 | |
| 122 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 123 | void X86Assembler::movl(const Address& dst, Register src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 124 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 125 | EmitUint8(0x89); |
| 126 | EmitOperand(src, dst); |
| 127 | } |
| 128 | |
| 129 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 130 | void X86Assembler::movl(const Address& dst, const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 131 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 132 | EmitUint8(0xC7); |
| 133 | EmitOperand(0, dst); |
| 134 | EmitImmediate(imm); |
| 135 | } |
| 136 | |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 137 | void X86Assembler::movl(const Address& dst, Label* lbl) { |
| 138 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 139 | EmitUint8(0xC7); |
| 140 | EmitOperand(0, dst); |
| 141 | EmitLabel(lbl, dst.length_ + 5); |
| 142 | } |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 143 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 144 | void X86Assembler::movzxb(Register dst, ByteRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 145 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 146 | EmitUint8(0x0F); |
| 147 | EmitUint8(0xB6); |
| 148 | EmitRegisterOperand(dst, src); |
| 149 | } |
| 150 | |
| 151 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 152 | void X86Assembler::movzxb(Register dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 153 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 154 | EmitUint8(0x0F); |
| 155 | EmitUint8(0xB6); |
| 156 | EmitOperand(dst, src); |
| 157 | } |
| 158 | |
| 159 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 160 | void X86Assembler::movsxb(Register dst, ByteRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 161 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 162 | EmitUint8(0x0F); |
| 163 | EmitUint8(0xBE); |
| 164 | EmitRegisterOperand(dst, src); |
| 165 | } |
| 166 | |
| 167 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 168 | void X86Assembler::movsxb(Register dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 169 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 170 | EmitUint8(0x0F); |
| 171 | EmitUint8(0xBE); |
| 172 | EmitOperand(dst, src); |
| 173 | } |
| 174 | |
| 175 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 176 | void X86Assembler::movb(Register dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 177 | LOG(FATAL) << "Use movzxb or movsxb instead."; |
| 178 | } |
| 179 | |
| 180 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 181 | void X86Assembler::movb(const Address& dst, ByteRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 182 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 183 | EmitUint8(0x88); |
| 184 | EmitOperand(src, dst); |
| 185 | } |
| 186 | |
| 187 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 188 | void X86Assembler::movb(const Address& dst, const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 189 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 190 | EmitUint8(0xC6); |
| 191 | EmitOperand(EAX, dst); |
| 192 | CHECK(imm.is_int8()); |
| 193 | EmitUint8(imm.value() & 0xFF); |
| 194 | } |
| 195 | |
| 196 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 197 | void X86Assembler::movzxw(Register dst, Register src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 198 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 199 | EmitUint8(0x0F); |
| 200 | EmitUint8(0xB7); |
| 201 | EmitRegisterOperand(dst, src); |
| 202 | } |
| 203 | |
| 204 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 205 | void X86Assembler::movzxw(Register dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 206 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 207 | EmitUint8(0x0F); |
| 208 | EmitUint8(0xB7); |
| 209 | EmitOperand(dst, src); |
| 210 | } |
| 211 | |
| 212 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 213 | void X86Assembler::movsxw(Register dst, Register src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 214 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 215 | EmitUint8(0x0F); |
| 216 | EmitUint8(0xBF); |
| 217 | EmitRegisterOperand(dst, src); |
| 218 | } |
| 219 | |
| 220 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 221 | void X86Assembler::movsxw(Register dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 222 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 223 | EmitUint8(0x0F); |
| 224 | EmitUint8(0xBF); |
| 225 | EmitOperand(dst, src); |
| 226 | } |
| 227 | |
| 228 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 229 | void X86Assembler::movw(Register dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 230 | LOG(FATAL) << "Use movzxw or movsxw instead."; |
| 231 | } |
| 232 | |
| 233 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 234 | void X86Assembler::movw(const Address& dst, Register src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 235 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 236 | EmitOperandSizeOverride(); |
| 237 | EmitUint8(0x89); |
| 238 | EmitOperand(src, dst); |
| 239 | } |
| 240 | |
| 241 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 242 | void X86Assembler::leal(Register dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 243 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 244 | EmitUint8(0x8D); |
| 245 | EmitOperand(dst, src); |
| 246 | } |
| 247 | |
| 248 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 249 | void X86Assembler::cmovl(Condition condition, Register dst, Register src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 250 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 251 | EmitUint8(0x0F); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 252 | EmitUint8(0x40 + condition); |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 253 | EmitRegisterOperand(dst, src); |
| 254 | } |
| 255 | |
| 256 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 257 | void X86Assembler::setb(Condition condition, Register dst) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 258 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 259 | EmitUint8(0x0F); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 260 | EmitUint8(0x90 + condition); |
| 261 | EmitOperand(0, Operand(dst)); |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 265 | void X86Assembler::movss(XmmRegister dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 266 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 267 | EmitUint8(0xF3); |
| 268 | EmitUint8(0x0F); |
| 269 | EmitUint8(0x10); |
| 270 | EmitOperand(dst, src); |
| 271 | } |
| 272 | |
| 273 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 274 | void X86Assembler::movss(const Address& dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 275 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 276 | EmitUint8(0xF3); |
| 277 | EmitUint8(0x0F); |
| 278 | EmitUint8(0x11); |
| 279 | EmitOperand(src, dst); |
| 280 | } |
| 281 | |
| 282 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 283 | void X86Assembler::movss(XmmRegister dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 284 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 285 | EmitUint8(0xF3); |
| 286 | EmitUint8(0x0F); |
| 287 | EmitUint8(0x11); |
| 288 | EmitXmmRegisterOperand(src, dst); |
| 289 | } |
| 290 | |
| 291 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 292 | void X86Assembler::movd(XmmRegister dst, Register src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 293 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 294 | EmitUint8(0x66); |
| 295 | EmitUint8(0x0F); |
| 296 | EmitUint8(0x6E); |
| 297 | EmitOperand(dst, Operand(src)); |
| 298 | } |
| 299 | |
| 300 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 301 | void X86Assembler::movd(Register dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 302 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 303 | EmitUint8(0x66); |
| 304 | EmitUint8(0x0F); |
| 305 | EmitUint8(0x7E); |
| 306 | EmitOperand(src, Operand(dst)); |
| 307 | } |
| 308 | |
| 309 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 310 | void X86Assembler::addss(XmmRegister dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 311 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 312 | EmitUint8(0xF3); |
| 313 | EmitUint8(0x0F); |
| 314 | EmitUint8(0x58); |
| 315 | EmitXmmRegisterOperand(dst, src); |
| 316 | } |
| 317 | |
| 318 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 319 | void X86Assembler::addss(XmmRegister dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 320 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 321 | EmitUint8(0xF3); |
| 322 | EmitUint8(0x0F); |
| 323 | EmitUint8(0x58); |
| 324 | EmitOperand(dst, src); |
| 325 | } |
| 326 | |
| 327 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 328 | void X86Assembler::subss(XmmRegister dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 329 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 330 | EmitUint8(0xF3); |
| 331 | EmitUint8(0x0F); |
| 332 | EmitUint8(0x5C); |
| 333 | EmitXmmRegisterOperand(dst, src); |
| 334 | } |
| 335 | |
| 336 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 337 | void X86Assembler::subss(XmmRegister dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 338 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 339 | EmitUint8(0xF3); |
| 340 | EmitUint8(0x0F); |
| 341 | EmitUint8(0x5C); |
| 342 | EmitOperand(dst, src); |
| 343 | } |
| 344 | |
| 345 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 346 | void X86Assembler::mulss(XmmRegister dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 347 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 348 | EmitUint8(0xF3); |
| 349 | EmitUint8(0x0F); |
| 350 | EmitUint8(0x59); |
| 351 | EmitXmmRegisterOperand(dst, src); |
| 352 | } |
| 353 | |
| 354 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 355 | void X86Assembler::mulss(XmmRegister dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 356 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 357 | EmitUint8(0xF3); |
| 358 | EmitUint8(0x0F); |
| 359 | EmitUint8(0x59); |
| 360 | EmitOperand(dst, src); |
| 361 | } |
| 362 | |
| 363 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 364 | void X86Assembler::divss(XmmRegister dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 365 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 366 | EmitUint8(0xF3); |
| 367 | EmitUint8(0x0F); |
| 368 | EmitUint8(0x5E); |
| 369 | EmitXmmRegisterOperand(dst, src); |
| 370 | } |
| 371 | |
| 372 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 373 | void X86Assembler::divss(XmmRegister dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 374 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 375 | EmitUint8(0xF3); |
| 376 | EmitUint8(0x0F); |
| 377 | EmitUint8(0x5E); |
| 378 | EmitOperand(dst, src); |
| 379 | } |
| 380 | |
| 381 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 382 | void X86Assembler::flds(const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 383 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 384 | EmitUint8(0xD9); |
| 385 | EmitOperand(0, src); |
| 386 | } |
| 387 | |
| 388 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 389 | void X86Assembler::fstps(const Address& dst) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 390 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 391 | EmitUint8(0xD9); |
| 392 | EmitOperand(3, dst); |
| 393 | } |
| 394 | |
| 395 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 396 | void X86Assembler::movsd(XmmRegister dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 397 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 398 | EmitUint8(0xF2); |
| 399 | EmitUint8(0x0F); |
| 400 | EmitUint8(0x10); |
| 401 | EmitOperand(dst, src); |
| 402 | } |
| 403 | |
| 404 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 405 | void X86Assembler::movsd(const Address& dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 406 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 407 | EmitUint8(0xF2); |
| 408 | EmitUint8(0x0F); |
| 409 | EmitUint8(0x11); |
| 410 | EmitOperand(src, dst); |
| 411 | } |
| 412 | |
| 413 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 414 | void X86Assembler::movsd(XmmRegister dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 415 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 416 | EmitUint8(0xF2); |
| 417 | EmitUint8(0x0F); |
| 418 | EmitUint8(0x11); |
| 419 | EmitXmmRegisterOperand(src, dst); |
| 420 | } |
| 421 | |
| 422 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 423 | void X86Assembler::addsd(XmmRegister dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 424 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 425 | EmitUint8(0xF2); |
| 426 | EmitUint8(0x0F); |
| 427 | EmitUint8(0x58); |
| 428 | EmitXmmRegisterOperand(dst, src); |
| 429 | } |
| 430 | |
| 431 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 432 | void X86Assembler::addsd(XmmRegister dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 433 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 434 | EmitUint8(0xF2); |
| 435 | EmitUint8(0x0F); |
| 436 | EmitUint8(0x58); |
| 437 | EmitOperand(dst, src); |
| 438 | } |
| 439 | |
| 440 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 441 | void X86Assembler::subsd(XmmRegister dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 442 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 443 | EmitUint8(0xF2); |
| 444 | EmitUint8(0x0F); |
| 445 | EmitUint8(0x5C); |
| 446 | EmitXmmRegisterOperand(dst, src); |
| 447 | } |
| 448 | |
| 449 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 450 | void X86Assembler::subsd(XmmRegister dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 451 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 452 | EmitUint8(0xF2); |
| 453 | EmitUint8(0x0F); |
| 454 | EmitUint8(0x5C); |
| 455 | EmitOperand(dst, src); |
| 456 | } |
| 457 | |
| 458 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 459 | void X86Assembler::mulsd(XmmRegister dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 460 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 461 | EmitUint8(0xF2); |
| 462 | EmitUint8(0x0F); |
| 463 | EmitUint8(0x59); |
| 464 | EmitXmmRegisterOperand(dst, src); |
| 465 | } |
| 466 | |
| 467 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 468 | void X86Assembler::mulsd(XmmRegister dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 469 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 470 | EmitUint8(0xF2); |
| 471 | EmitUint8(0x0F); |
| 472 | EmitUint8(0x59); |
| 473 | EmitOperand(dst, src); |
| 474 | } |
| 475 | |
| 476 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 477 | void X86Assembler::divsd(XmmRegister dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 478 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 479 | EmitUint8(0xF2); |
| 480 | EmitUint8(0x0F); |
| 481 | EmitUint8(0x5E); |
| 482 | EmitXmmRegisterOperand(dst, src); |
| 483 | } |
| 484 | |
| 485 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 486 | void X86Assembler::divsd(XmmRegister dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 487 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 488 | EmitUint8(0xF2); |
| 489 | EmitUint8(0x0F); |
| 490 | EmitUint8(0x5E); |
| 491 | EmitOperand(dst, src); |
| 492 | } |
| 493 | |
| 494 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 495 | void X86Assembler::cvtsi2ss(XmmRegister dst, Register src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 496 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 497 | EmitUint8(0xF3); |
| 498 | EmitUint8(0x0F); |
| 499 | EmitUint8(0x2A); |
| 500 | EmitOperand(dst, Operand(src)); |
| 501 | } |
| 502 | |
| 503 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 504 | void X86Assembler::cvtsi2sd(XmmRegister dst, Register src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 505 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 506 | EmitUint8(0xF2); |
| 507 | EmitUint8(0x0F); |
| 508 | EmitUint8(0x2A); |
| 509 | EmitOperand(dst, Operand(src)); |
| 510 | } |
| 511 | |
| 512 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 513 | void X86Assembler::cvtss2si(Register dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 514 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 515 | EmitUint8(0xF3); |
| 516 | EmitUint8(0x0F); |
| 517 | EmitUint8(0x2D); |
| 518 | EmitXmmRegisterOperand(dst, src); |
| 519 | } |
| 520 | |
| 521 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 522 | void X86Assembler::cvtss2sd(XmmRegister dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 523 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 524 | EmitUint8(0xF3); |
| 525 | EmitUint8(0x0F); |
| 526 | EmitUint8(0x5A); |
| 527 | EmitXmmRegisterOperand(dst, src); |
| 528 | } |
| 529 | |
| 530 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 531 | void X86Assembler::cvtsd2si(Register dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 532 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 533 | EmitUint8(0xF2); |
| 534 | EmitUint8(0x0F); |
| 535 | EmitUint8(0x2D); |
| 536 | EmitXmmRegisterOperand(dst, src); |
| 537 | } |
| 538 | |
| 539 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 540 | void X86Assembler::cvttss2si(Register dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 541 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 542 | EmitUint8(0xF3); |
| 543 | EmitUint8(0x0F); |
| 544 | EmitUint8(0x2C); |
| 545 | EmitXmmRegisterOperand(dst, src); |
| 546 | } |
| 547 | |
| 548 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 549 | void X86Assembler::cvttsd2si(Register dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 550 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 551 | EmitUint8(0xF2); |
| 552 | EmitUint8(0x0F); |
| 553 | EmitUint8(0x2C); |
| 554 | EmitXmmRegisterOperand(dst, src); |
| 555 | } |
| 556 | |
| 557 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 558 | void X86Assembler::cvtsd2ss(XmmRegister dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 559 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 560 | EmitUint8(0xF2); |
| 561 | EmitUint8(0x0F); |
| 562 | EmitUint8(0x5A); |
| 563 | EmitXmmRegisterOperand(dst, src); |
| 564 | } |
| 565 | |
| 566 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 567 | void X86Assembler::cvtdq2pd(XmmRegister dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 568 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 569 | EmitUint8(0xF3); |
| 570 | EmitUint8(0x0F); |
| 571 | EmitUint8(0xE6); |
| 572 | EmitXmmRegisterOperand(dst, src); |
| 573 | } |
| 574 | |
| 575 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 576 | void X86Assembler::comiss(XmmRegister a, XmmRegister b) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 577 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 578 | EmitUint8(0x0F); |
| 579 | EmitUint8(0x2F); |
| 580 | EmitXmmRegisterOperand(a, b); |
| 581 | } |
| 582 | |
| 583 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 584 | void X86Assembler::comisd(XmmRegister a, XmmRegister b) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 585 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 586 | EmitUint8(0x66); |
| 587 | EmitUint8(0x0F); |
| 588 | EmitUint8(0x2F); |
| 589 | EmitXmmRegisterOperand(a, b); |
| 590 | } |
| 591 | |
| 592 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 593 | void X86Assembler::sqrtsd(XmmRegister dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 594 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 595 | EmitUint8(0xF2); |
| 596 | EmitUint8(0x0F); |
| 597 | EmitUint8(0x51); |
| 598 | EmitXmmRegisterOperand(dst, src); |
| 599 | } |
| 600 | |
| 601 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 602 | void X86Assembler::sqrtss(XmmRegister dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 603 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 604 | EmitUint8(0xF3); |
| 605 | EmitUint8(0x0F); |
| 606 | EmitUint8(0x51); |
| 607 | EmitXmmRegisterOperand(dst, src); |
| 608 | } |
| 609 | |
| 610 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 611 | void X86Assembler::xorpd(XmmRegister dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 612 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 613 | EmitUint8(0x66); |
| 614 | EmitUint8(0x0F); |
| 615 | EmitUint8(0x57); |
| 616 | EmitOperand(dst, src); |
| 617 | } |
| 618 | |
| 619 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 620 | void X86Assembler::xorpd(XmmRegister dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 621 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 622 | EmitUint8(0x66); |
| 623 | EmitUint8(0x0F); |
| 624 | EmitUint8(0x57); |
| 625 | EmitXmmRegisterOperand(dst, src); |
| 626 | } |
| 627 | |
| 628 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 629 | void X86Assembler::xorps(XmmRegister dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 630 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 631 | EmitUint8(0x0F); |
| 632 | EmitUint8(0x57); |
| 633 | EmitOperand(dst, src); |
| 634 | } |
| 635 | |
| 636 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 637 | void X86Assembler::xorps(XmmRegister dst, XmmRegister src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 638 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 639 | EmitUint8(0x0F); |
| 640 | EmitUint8(0x57); |
| 641 | EmitXmmRegisterOperand(dst, src); |
| 642 | } |
| 643 | |
| 644 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 645 | void X86Assembler::andpd(XmmRegister dst, const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 646 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 647 | EmitUint8(0x66); |
| 648 | EmitUint8(0x0F); |
| 649 | EmitUint8(0x54); |
| 650 | EmitOperand(dst, src); |
| 651 | } |
| 652 | |
| 653 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 654 | void X86Assembler::fldl(const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 655 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 656 | EmitUint8(0xDD); |
| 657 | EmitOperand(0, src); |
| 658 | } |
| 659 | |
| 660 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 661 | void X86Assembler::fstpl(const Address& dst) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 662 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 663 | EmitUint8(0xDD); |
| 664 | EmitOperand(3, dst); |
| 665 | } |
| 666 | |
| 667 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 668 | void X86Assembler::fnstcw(const Address& dst) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 669 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 670 | EmitUint8(0xD9); |
| 671 | EmitOperand(7, dst); |
| 672 | } |
| 673 | |
| 674 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 675 | void X86Assembler::fldcw(const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 676 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 677 | EmitUint8(0xD9); |
| 678 | EmitOperand(5, src); |
| 679 | } |
| 680 | |
| 681 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 682 | void X86Assembler::fistpl(const Address& dst) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 683 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 684 | EmitUint8(0xDF); |
| 685 | EmitOperand(7, dst); |
| 686 | } |
| 687 | |
| 688 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 689 | void X86Assembler::fistps(const Address& dst) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 690 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 691 | EmitUint8(0xDB); |
| 692 | EmitOperand(3, dst); |
| 693 | } |
| 694 | |
| 695 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 696 | void X86Assembler::fildl(const Address& src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 697 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 698 | EmitUint8(0xDF); |
| 699 | EmitOperand(5, src); |
| 700 | } |
| 701 | |
| 702 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 703 | void X86Assembler::fincstp() { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 704 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 705 | EmitUint8(0xD9); |
| 706 | EmitUint8(0xF7); |
| 707 | } |
| 708 | |
| 709 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 710 | void X86Assembler::ffree(const Immediate& index) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 711 | CHECK_LT(index.value(), 7); |
| 712 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 713 | EmitUint8(0xDD); |
| 714 | EmitUint8(0xC0 + index.value()); |
| 715 | } |
| 716 | |
| 717 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 718 | void X86Assembler::fsin() { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 719 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 720 | EmitUint8(0xD9); |
| 721 | EmitUint8(0xFE); |
| 722 | } |
| 723 | |
| 724 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 725 | void X86Assembler::fcos() { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 726 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 727 | EmitUint8(0xD9); |
| 728 | EmitUint8(0xFF); |
| 729 | } |
| 730 | |
| 731 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 732 | void X86Assembler::fptan() { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 733 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 734 | EmitUint8(0xD9); |
| 735 | EmitUint8(0xF2); |
| 736 | } |
| 737 | |
| 738 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 739 | void X86Assembler::xchgl(Register dst, Register src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 740 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 741 | EmitUint8(0x87); |
| 742 | EmitRegisterOperand(dst, src); |
| 743 | } |
| 744 | |
| 745 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 746 | void X86Assembler::cmpl(Register reg, const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 747 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 748 | EmitComplex(7, Operand(reg), imm); |
| 749 | } |
| 750 | |
| 751 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 752 | void X86Assembler::cmpl(Register reg0, Register reg1) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 753 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 754 | EmitUint8(0x3B); |
| 755 | EmitOperand(reg0, Operand(reg1)); |
| 756 | } |
| 757 | |
| 758 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 759 | void X86Assembler::cmpl(Register reg, const Address& address) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 760 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 761 | EmitUint8(0x3B); |
| 762 | EmitOperand(reg, address); |
| 763 | } |
| 764 | |
| 765 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 766 | void X86Assembler::addl(Register dst, Register src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 767 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 768 | EmitUint8(0x03); |
| 769 | EmitRegisterOperand(dst, src); |
| 770 | } |
| 771 | |
| 772 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 773 | void X86Assembler::addl(Register reg, const Address& address) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 774 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 775 | EmitUint8(0x03); |
| 776 | EmitOperand(reg, address); |
| 777 | } |
| 778 | |
| 779 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 780 | void X86Assembler::cmpl(const Address& address, Register reg) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 781 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 782 | EmitUint8(0x39); |
| 783 | EmitOperand(reg, address); |
| 784 | } |
| 785 | |
| 786 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 787 | void X86Assembler::cmpl(const Address& address, const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 788 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 789 | EmitComplex(7, address, imm); |
| 790 | } |
| 791 | |
| 792 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 793 | void X86Assembler::testl(Register reg1, Register reg2) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 794 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 795 | EmitUint8(0x85); |
| 796 | EmitRegisterOperand(reg1, reg2); |
| 797 | } |
| 798 | |
| 799 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 800 | void X86Assembler::testl(Register reg, const Immediate& immediate) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 801 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 802 | // For registers that have a byte variant (EAX, EBX, ECX, and EDX) |
| 803 | // we only test the byte register to keep the encoding short. |
| 804 | if (immediate.is_uint8() && reg < 4) { |
| 805 | // Use zero-extended 8-bit immediate. |
| 806 | if (reg == EAX) { |
| 807 | EmitUint8(0xA8); |
| 808 | } else { |
| 809 | EmitUint8(0xF6); |
| 810 | EmitUint8(0xC0 + reg); |
| 811 | } |
| 812 | EmitUint8(immediate.value() & 0xFF); |
| 813 | } else if (reg == EAX) { |
| 814 | // Use short form if the destination is EAX. |
| 815 | EmitUint8(0xA9); |
| 816 | EmitImmediate(immediate); |
| 817 | } else { |
| 818 | EmitUint8(0xF7); |
| 819 | EmitOperand(0, Operand(reg)); |
| 820 | EmitImmediate(immediate); |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 825 | void X86Assembler::andl(Register dst, Register src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 826 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 827 | EmitUint8(0x23); |
| 828 | EmitOperand(dst, Operand(src)); |
| 829 | } |
| 830 | |
| 831 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 832 | void X86Assembler::andl(Register dst, const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 833 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 834 | EmitComplex(4, Operand(dst), imm); |
| 835 | } |
| 836 | |
| 837 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 838 | void X86Assembler::orl(Register dst, Register src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 839 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 840 | EmitUint8(0x0B); |
| 841 | EmitOperand(dst, Operand(src)); |
| 842 | } |
| 843 | |
| 844 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 845 | void X86Assembler::orl(Register dst, const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 846 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 847 | EmitComplex(1, Operand(dst), imm); |
| 848 | } |
| 849 | |
| 850 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 851 | void X86Assembler::xorl(Register dst, Register src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 852 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 853 | EmitUint8(0x33); |
| 854 | EmitOperand(dst, Operand(src)); |
| 855 | } |
| 856 | |
| 857 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 858 | void X86Assembler::addl(Register reg, const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 859 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 860 | EmitComplex(0, Operand(reg), imm); |
| 861 | } |
| 862 | |
| 863 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 864 | void X86Assembler::addl(const Address& address, Register reg) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 865 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 866 | EmitUint8(0x01); |
| 867 | EmitOperand(reg, address); |
| 868 | } |
| 869 | |
| 870 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 871 | void X86Assembler::addl(const Address& address, const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 872 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 873 | EmitComplex(0, address, imm); |
| 874 | } |
| 875 | |
| 876 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 877 | void X86Assembler::adcl(Register reg, const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 878 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 879 | EmitComplex(2, Operand(reg), imm); |
| 880 | } |
| 881 | |
| 882 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 883 | void X86Assembler::adcl(Register dst, Register src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 884 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 885 | EmitUint8(0x13); |
| 886 | EmitOperand(dst, Operand(src)); |
| 887 | } |
| 888 | |
| 889 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 890 | void X86Assembler::adcl(Register dst, const Address& address) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 891 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 892 | EmitUint8(0x13); |
| 893 | EmitOperand(dst, address); |
| 894 | } |
| 895 | |
| 896 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 897 | void X86Assembler::subl(Register dst, Register src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 898 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 899 | EmitUint8(0x2B); |
| 900 | EmitOperand(dst, Operand(src)); |
| 901 | } |
| 902 | |
| 903 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 904 | void X86Assembler::subl(Register reg, const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 905 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 906 | EmitComplex(5, Operand(reg), imm); |
| 907 | } |
| 908 | |
| 909 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 910 | void X86Assembler::subl(Register reg, const Address& address) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 911 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 912 | EmitUint8(0x2B); |
| 913 | EmitOperand(reg, address); |
| 914 | } |
| 915 | |
| 916 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 917 | void X86Assembler::cdq() { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 918 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 919 | EmitUint8(0x99); |
| 920 | } |
| 921 | |
| 922 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 923 | void X86Assembler::idivl(Register reg) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 924 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 925 | EmitUint8(0xF7); |
| 926 | EmitUint8(0xF8 | reg); |
| 927 | } |
| 928 | |
| 929 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 930 | void X86Assembler::imull(Register dst, Register src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 931 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 932 | EmitUint8(0x0F); |
| 933 | EmitUint8(0xAF); |
| 934 | EmitOperand(dst, Operand(src)); |
| 935 | } |
| 936 | |
| 937 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 938 | void X86Assembler::imull(Register reg, const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 939 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 940 | EmitUint8(0x69); |
| 941 | EmitOperand(reg, Operand(reg)); |
| 942 | EmitImmediate(imm); |
| 943 | } |
| 944 | |
| 945 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 946 | void X86Assembler::imull(Register reg, const Address& address) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 947 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 948 | EmitUint8(0x0F); |
| 949 | EmitUint8(0xAF); |
| 950 | EmitOperand(reg, address); |
| 951 | } |
| 952 | |
| 953 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 954 | void X86Assembler::imull(Register reg) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 955 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 956 | EmitUint8(0xF7); |
| 957 | EmitOperand(5, Operand(reg)); |
| 958 | } |
| 959 | |
| 960 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 961 | void X86Assembler::imull(const Address& address) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 962 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 963 | EmitUint8(0xF7); |
| 964 | EmitOperand(5, address); |
| 965 | } |
| 966 | |
| 967 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 968 | void X86Assembler::mull(Register reg) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 969 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 970 | EmitUint8(0xF7); |
| 971 | EmitOperand(4, Operand(reg)); |
| 972 | } |
| 973 | |
| 974 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 975 | void X86Assembler::mull(const Address& address) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 976 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 977 | EmitUint8(0xF7); |
| 978 | EmitOperand(4, address); |
| 979 | } |
| 980 | |
| 981 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 982 | void X86Assembler::sbbl(Register dst, Register src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 983 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 984 | EmitUint8(0x1B); |
| 985 | EmitOperand(dst, Operand(src)); |
| 986 | } |
| 987 | |
| 988 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 989 | void X86Assembler::sbbl(Register reg, const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 990 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 991 | EmitComplex(3, Operand(reg), imm); |
| 992 | } |
| 993 | |
| 994 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 995 | void X86Assembler::sbbl(Register dst, const Address& address) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 996 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 997 | EmitUint8(0x1B); |
| 998 | EmitOperand(dst, address); |
| 999 | } |
| 1000 | |
| 1001 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1002 | void X86Assembler::incl(Register reg) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1003 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1004 | EmitUint8(0x40 + reg); |
| 1005 | } |
| 1006 | |
| 1007 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1008 | void X86Assembler::incl(const Address& address) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1009 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1010 | EmitUint8(0xFF); |
| 1011 | EmitOperand(0, address); |
| 1012 | } |
| 1013 | |
| 1014 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1015 | void X86Assembler::decl(Register reg) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1016 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1017 | EmitUint8(0x48 + reg); |
| 1018 | } |
| 1019 | |
| 1020 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1021 | void X86Assembler::decl(const Address& address) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1022 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1023 | EmitUint8(0xFF); |
| 1024 | EmitOperand(1, address); |
| 1025 | } |
| 1026 | |
| 1027 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1028 | void X86Assembler::shll(Register reg, const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1029 | EmitGenericShift(4, reg, imm); |
| 1030 | } |
| 1031 | |
| 1032 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1033 | void X86Assembler::shll(Register operand, Register shifter) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1034 | EmitGenericShift(4, operand, shifter); |
| 1035 | } |
| 1036 | |
| 1037 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1038 | void X86Assembler::shrl(Register reg, const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1039 | EmitGenericShift(5, reg, imm); |
| 1040 | } |
| 1041 | |
| 1042 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1043 | void X86Assembler::shrl(Register operand, Register shifter) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1044 | EmitGenericShift(5, operand, shifter); |
| 1045 | } |
| 1046 | |
| 1047 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1048 | void X86Assembler::sarl(Register reg, const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1049 | EmitGenericShift(7, reg, imm); |
| 1050 | } |
| 1051 | |
| 1052 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1053 | void X86Assembler::sarl(Register operand, Register shifter) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1054 | EmitGenericShift(7, operand, shifter); |
| 1055 | } |
| 1056 | |
| 1057 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1058 | void X86Assembler::shld(Register dst, Register src) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1059 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1060 | EmitUint8(0x0F); |
| 1061 | EmitUint8(0xA5); |
| 1062 | EmitRegisterOperand(src, dst); |
| 1063 | } |
| 1064 | |
| 1065 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1066 | void X86Assembler::negl(Register reg) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1067 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1068 | EmitUint8(0xF7); |
| 1069 | EmitOperand(3, Operand(reg)); |
| 1070 | } |
| 1071 | |
| 1072 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1073 | void X86Assembler::notl(Register reg) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1074 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1075 | EmitUint8(0xF7); |
| 1076 | EmitUint8(0xD0 | reg); |
| 1077 | } |
| 1078 | |
| 1079 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1080 | void X86Assembler::enter(const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1081 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1082 | EmitUint8(0xC8); |
| 1083 | CHECK(imm.is_uint16()); |
| 1084 | EmitUint8(imm.value() & 0xFF); |
| 1085 | EmitUint8((imm.value() >> 8) & 0xFF); |
| 1086 | EmitUint8(0x00); |
| 1087 | } |
| 1088 | |
| 1089 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1090 | void X86Assembler::leave() { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1091 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1092 | EmitUint8(0xC9); |
| 1093 | } |
| 1094 | |
| 1095 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1096 | void X86Assembler::ret() { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1097 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1098 | EmitUint8(0xC3); |
| 1099 | } |
| 1100 | |
| 1101 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1102 | void X86Assembler::ret(const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1103 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1104 | EmitUint8(0xC2); |
| 1105 | CHECK(imm.is_uint16()); |
| 1106 | EmitUint8(imm.value() & 0xFF); |
| 1107 | EmitUint8((imm.value() >> 8) & 0xFF); |
| 1108 | } |
| 1109 | |
| 1110 | |
| 1111 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1112 | void X86Assembler::nop() { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1113 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1114 | EmitUint8(0x90); |
| 1115 | } |
| 1116 | |
| 1117 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1118 | void X86Assembler::int3() { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1119 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1120 | EmitUint8(0xCC); |
| 1121 | } |
| 1122 | |
| 1123 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1124 | void X86Assembler::hlt() { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1125 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1126 | EmitUint8(0xF4); |
| 1127 | } |
| 1128 | |
| 1129 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1130 | void X86Assembler::j(Condition condition, Label* label) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1131 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1132 | if (label->IsBound()) { |
| 1133 | static const int kShortSize = 2; |
| 1134 | static const int kLongSize = 6; |
| 1135 | int offset = label->Position() - buffer_.Size(); |
| 1136 | CHECK_LE(offset, 0); |
| 1137 | if (IsInt(8, offset - kShortSize)) { |
| 1138 | EmitUint8(0x70 + condition); |
| 1139 | EmitUint8((offset - kShortSize) & 0xFF); |
| 1140 | } else { |
| 1141 | EmitUint8(0x0F); |
| 1142 | EmitUint8(0x80 + condition); |
| 1143 | EmitInt32(offset - kLongSize); |
| 1144 | } |
| 1145 | } else { |
| 1146 | EmitUint8(0x0F); |
| 1147 | EmitUint8(0x80 + condition); |
| 1148 | EmitLabelLink(label); |
| 1149 | } |
| 1150 | } |
| 1151 | |
| 1152 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1153 | void X86Assembler::jmp(Register reg) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1154 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1155 | EmitUint8(0xFF); |
| 1156 | EmitRegisterOperand(4, reg); |
| 1157 | } |
| 1158 | |
| 1159 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1160 | void X86Assembler::jmp(Label* label) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1161 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1162 | if (label->IsBound()) { |
| 1163 | static const int kShortSize = 2; |
| 1164 | static const int kLongSize = 5; |
| 1165 | int offset = label->Position() - buffer_.Size(); |
| 1166 | CHECK_LE(offset, 0); |
| 1167 | if (IsInt(8, offset - kShortSize)) { |
| 1168 | EmitUint8(0xEB); |
| 1169 | EmitUint8((offset - kShortSize) & 0xFF); |
| 1170 | } else { |
| 1171 | EmitUint8(0xE9); |
| 1172 | EmitInt32(offset - kLongSize); |
| 1173 | } |
| 1174 | } else { |
| 1175 | EmitUint8(0xE9); |
| 1176 | EmitLabelLink(label); |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1181 | X86Assembler* X86Assembler::lock() { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1182 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1183 | EmitUint8(0xF0); |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 1184 | return this; |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1188 | void X86Assembler::cmpxchgl(const Address& address, Register reg) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1189 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1190 | EmitUint8(0x0F); |
| 1191 | EmitUint8(0xB1); |
| 1192 | EmitOperand(reg, address); |
| 1193 | } |
| 1194 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1195 | X86Assembler* X86Assembler::fs() { |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1196 | // TODO: fs is a prefix and not an instruction |
| 1197 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1198 | EmitUint8(0x64); |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 1199 | return this; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1200 | } |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1201 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1202 | void X86Assembler::AddImmediate(Register reg, const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1203 | int value = imm.value(); |
| 1204 | if (value > 0) { |
| 1205 | if (value == 1) { |
| 1206 | incl(reg); |
| 1207 | } else if (value != 0) { |
| 1208 | addl(reg, imm); |
| 1209 | } |
| 1210 | } else if (value < 0) { |
| 1211 | value = -value; |
| 1212 | if (value == 1) { |
| 1213 | decl(reg); |
| 1214 | } else if (value != 0) { |
| 1215 | subl(reg, Immediate(value)); |
| 1216 | } |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1221 | void X86Assembler::LoadDoubleConstant(XmmRegister dst, double value) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1222 | // TODO: Need to have a code constants table. |
| 1223 | int64_t constant = bit_cast<int64_t, double>(value); |
| 1224 | pushl(Immediate(High32Bits(constant))); |
| 1225 | pushl(Immediate(Low32Bits(constant))); |
| 1226 | movsd(dst, Address(ESP, 0)); |
| 1227 | addl(ESP, Immediate(2 * kWordSize)); |
| 1228 | } |
| 1229 | |
| 1230 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1231 | void X86Assembler::FloatNegate(XmmRegister f) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1232 | static const struct { |
| 1233 | uint32_t a; |
| 1234 | uint32_t b; |
| 1235 | uint32_t c; |
| 1236 | uint32_t d; |
| 1237 | } float_negate_constant __attribute__((aligned(16))) = |
| 1238 | { 0x80000000, 0x00000000, 0x80000000, 0x00000000 }; |
| 1239 | xorps(f, Address::Absolute(reinterpret_cast<uword>(&float_negate_constant))); |
| 1240 | } |
| 1241 | |
| 1242 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1243 | void X86Assembler::DoubleNegate(XmmRegister d) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1244 | static const struct { |
| 1245 | uint64_t a; |
| 1246 | uint64_t b; |
| 1247 | } double_negate_constant __attribute__((aligned(16))) = |
| 1248 | {0x8000000000000000LL, 0x8000000000000000LL}; |
| 1249 | xorpd(d, Address::Absolute(reinterpret_cast<uword>(&double_negate_constant))); |
| 1250 | } |
| 1251 | |
| 1252 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1253 | void X86Assembler::DoubleAbs(XmmRegister reg) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1254 | static const struct { |
| 1255 | uint64_t a; |
| 1256 | uint64_t b; |
| 1257 | } double_abs_constant __attribute__((aligned(16))) = |
| 1258 | {0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFFLL}; |
| 1259 | andpd(reg, Address::Absolute(reinterpret_cast<uword>(&double_abs_constant))); |
| 1260 | } |
| 1261 | |
| 1262 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1263 | void X86Assembler::Align(int alignment, int offset) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1264 | CHECK(IsPowerOfTwo(alignment)); |
| 1265 | // Emit nop instruction until the real position is aligned. |
| 1266 | while (((offset + buffer_.GetPosition()) & (alignment-1)) != 0) { |
| 1267 | nop(); |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1272 | void X86Assembler::Bind(Label* label) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1273 | int bound = buffer_.Size(); |
| 1274 | CHECK(!label->IsBound()); // Labels can only be bound once. |
| 1275 | while (label->IsLinked()) { |
| 1276 | int position = label->LinkPosition(); |
| 1277 | int next = buffer_.Load<int32_t>(position); |
| 1278 | buffer_.Store<int32_t>(position, bound - (position + 4)); |
| 1279 | label->position_ = next; |
| 1280 | } |
| 1281 | label->BindTo(bound); |
| 1282 | } |
| 1283 | |
| 1284 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1285 | void X86Assembler::Stop(const char* message) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1286 | // Emit the message address as immediate operand in the test rax instruction, |
| 1287 | // followed by the int3 instruction. |
| 1288 | // Execution can be resumed with the 'cont' command in gdb. |
| 1289 | testl(EAX, Immediate(reinterpret_cast<int32_t>(message))); |
| 1290 | int3(); |
| 1291 | } |
| 1292 | |
| 1293 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1294 | void X86Assembler::EmitOperand(int rm, const Operand& operand) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1295 | CHECK_GE(rm, 0); |
| 1296 | CHECK_LT(rm, 8); |
| 1297 | const int length = operand.length_; |
| 1298 | CHECK_GT(length, 0); |
| 1299 | // Emit the ModRM byte updated with the given RM value. |
| 1300 | CHECK_EQ(operand.encoding_[0] & 0x38, 0); |
| 1301 | EmitUint8(operand.encoding_[0] + (rm << 3)); |
| 1302 | // Emit the rest of the encoded operand. |
| 1303 | for (int i = 1; i < length; i++) { |
| 1304 | EmitUint8(operand.encoding_[i]); |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1309 | void X86Assembler::EmitImmediate(const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1310 | EmitInt32(imm.value()); |
| 1311 | } |
| 1312 | |
| 1313 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1314 | void X86Assembler::EmitComplex(int rm, |
| 1315 | const Operand& operand, |
| 1316 | const Immediate& immediate) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1317 | CHECK_GE(rm, 0); |
| 1318 | CHECK_LT(rm, 8); |
| 1319 | if (immediate.is_int8()) { |
| 1320 | // Use sign-extended 8-bit immediate. |
| 1321 | EmitUint8(0x83); |
| 1322 | EmitOperand(rm, operand); |
| 1323 | EmitUint8(immediate.value() & 0xFF); |
| 1324 | } else if (operand.IsRegister(EAX)) { |
| 1325 | // Use short form if the destination is eax. |
| 1326 | EmitUint8(0x05 + (rm << 3)); |
| 1327 | EmitImmediate(immediate); |
| 1328 | } else { |
| 1329 | EmitUint8(0x81); |
| 1330 | EmitOperand(rm, operand); |
| 1331 | EmitImmediate(immediate); |
| 1332 | } |
| 1333 | } |
| 1334 | |
| 1335 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1336 | void X86Assembler::EmitLabel(Label* label, int instruction_size) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1337 | if (label->IsBound()) { |
| 1338 | int offset = label->Position() - buffer_.Size(); |
| 1339 | CHECK_LE(offset, 0); |
| 1340 | EmitInt32(offset - instruction_size); |
| 1341 | } else { |
| 1342 | EmitLabelLink(label); |
| 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1347 | void X86Assembler::EmitLabelLink(Label* label) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1348 | CHECK(!label->IsBound()); |
| 1349 | int position = buffer_.Size(); |
| 1350 | EmitInt32(label->position_); |
| 1351 | label->LinkTo(position); |
| 1352 | } |
| 1353 | |
| 1354 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1355 | void X86Assembler::EmitGenericShift(int rm, |
| 1356 | Register reg, |
| 1357 | const Immediate& imm) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1358 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1359 | CHECK(imm.is_int8()); |
| 1360 | if (imm.value() == 1) { |
| 1361 | EmitUint8(0xD1); |
| 1362 | EmitOperand(rm, Operand(reg)); |
| 1363 | } else { |
| 1364 | EmitUint8(0xC1); |
| 1365 | EmitOperand(rm, Operand(reg)); |
| 1366 | EmitUint8(imm.value() & 0xFF); |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1371 | void X86Assembler::EmitGenericShift(int rm, |
| 1372 | Register operand, |
| 1373 | Register shifter) { |
Carl Shapiro | a5d5cfd | 2011-06-21 12:46:59 -0700 | [diff] [blame] | 1374 | AssemblerBuffer::EnsureCapacity ensured(&buffer_); |
| 1375 | CHECK_EQ(shifter, ECX); |
| 1376 | EmitUint8(0xD3); |
| 1377 | EmitOperand(rm, Operand(operand)); |
| 1378 | } |
| 1379 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1380 | void X86Assembler::BuildFrame(size_t frame_size, ManagedRegister method_reg, |
| 1381 | const std::vector<ManagedRegister>& spill_regs) { |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 1382 | CHECK(IsAligned(frame_size, kStackAlignment)); |
| 1383 | CHECK_EQ(0u, spill_regs.size()); // no spilled regs on x86 |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1384 | // return address then method on stack |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 1385 | addl(ESP, Immediate(-frame_size + kPointerSize /*method*/ + |
| 1386 | kPointerSize /*return address*/)); |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1387 | pushl(method_reg.AsX86().AsCpuRegister()); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1390 | void X86Assembler::RemoveFrame(size_t frame_size, |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 1391 | const std::vector<ManagedRegister>& spill_regs) { |
| 1392 | CHECK(IsAligned(frame_size, kStackAlignment)); |
| 1393 | CHECK_EQ(0u, spill_regs.size()); // no spilled regs on x86 |
| 1394 | addl(ESP, Immediate(frame_size - kPointerSize)); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1395 | ret(); |
| 1396 | } |
| 1397 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1398 | void X86Assembler::IncreaseFrameSize(size_t adjust) { |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 1399 | CHECK(IsAligned(adjust, kStackAlignment)); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1400 | addl(ESP, Immediate(-adjust)); |
| 1401 | } |
| 1402 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1403 | void X86Assembler::DecreaseFrameSize(size_t adjust) { |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 1404 | CHECK(IsAligned(adjust, kStackAlignment)); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1405 | addl(ESP, Immediate(adjust)); |
| 1406 | } |
| 1407 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1408 | void X86Assembler::Store(FrameOffset offs, ManagedRegister msrc, size_t size) { |
| 1409 | X86ManagedRegister src = msrc.AsX86(); |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 1410 | if (src.IsNoRegister()) { |
| 1411 | CHECK_EQ(0u, size); |
| 1412 | } else if (src.IsCpuRegister()) { |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1413 | CHECK_EQ(4u, size); |
| 1414 | movl(Address(ESP, offs), src.AsCpuRegister()); |
Ian Rogers | 9b269d2 | 2011-09-04 14:06:05 -0700 | [diff] [blame] | 1415 | } else if (src.IsRegisterPair()) { |
| 1416 | CHECK_EQ(8u, size); |
| 1417 | movl(Address(ESP, offs), src.AsRegisterPairLow()); |
| 1418 | movl(Address(ESP, FrameOffset(offs.Int32Value()+4)), |
| 1419 | src.AsRegisterPairHigh()); |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 1420 | } else if (src.IsX87Register()) { |
| 1421 | if (size == 4) { |
| 1422 | fstps(Address(ESP, offs)); |
| 1423 | } else { |
| 1424 | fstpl(Address(ESP, offs)); |
| 1425 | } |
| 1426 | } else { |
| 1427 | CHECK(src.IsXmmRegister()); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1428 | if (size == 4) { |
| 1429 | movss(Address(ESP, offs), src.AsXmmRegister()); |
| 1430 | } else { |
| 1431 | movsd(Address(ESP, offs), src.AsXmmRegister()); |
| 1432 | } |
| 1433 | } |
| 1434 | } |
| 1435 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1436 | void X86Assembler::StoreRef(FrameOffset dest, ManagedRegister msrc) { |
| 1437 | X86ManagedRegister src = msrc.AsX86(); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1438 | CHECK(src.IsCpuRegister()); |
| 1439 | movl(Address(ESP, dest), src.AsCpuRegister()); |
| 1440 | } |
| 1441 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1442 | void X86Assembler::StoreRawPtr(FrameOffset dest, ManagedRegister msrc) { |
| 1443 | X86ManagedRegister src = msrc.AsX86(); |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 1444 | CHECK(src.IsCpuRegister()); |
| 1445 | movl(Address(ESP, dest), src.AsCpuRegister()); |
| 1446 | } |
| 1447 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1448 | void X86Assembler::StoreImmediateToFrame(FrameOffset dest, uint32_t imm, |
| 1449 | ManagedRegister) { |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1450 | movl(Address(ESP, dest), Immediate(imm)); |
| 1451 | } |
| 1452 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1453 | void X86Assembler::StoreImmediateToThread(ThreadOffset dest, uint32_t imm, |
| 1454 | ManagedRegister) { |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 1455 | fs()->movl(Address::Absolute(dest), Immediate(imm)); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1456 | } |
| 1457 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1458 | void X86Assembler::StoreStackOffsetToThread(ThreadOffset thr_offs, |
| 1459 | FrameOffset fr_offs, |
| 1460 | ManagedRegister mscratch) { |
| 1461 | X86ManagedRegister scratch = mscratch.AsX86(); |
| 1462 | CHECK(scratch.IsCpuRegister()); |
| 1463 | leal(scratch.AsCpuRegister(), Address(ESP, fr_offs)); |
| 1464 | fs()->movl(Address::Absolute(thr_offs), scratch.AsCpuRegister()); |
| 1465 | } |
| 1466 | |
| 1467 | void X86Assembler::StoreStackPointerToThread(ThreadOffset thr_offs) { |
| 1468 | fs()->movl(Address::Absolute(thr_offs), ESP); |
| 1469 | } |
| 1470 | |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 1471 | void X86Assembler::StoreLabelToThread(ThreadOffset thr_offs, Label* lbl) { |
| 1472 | fs()->movl(Address::Absolute(thr_offs), lbl); |
| 1473 | } |
| 1474 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1475 | void X86Assembler::StoreSpanning(FrameOffset dest, ManagedRegister src, |
| 1476 | FrameOffset in_off, ManagedRegister scratch) { |
| 1477 | UNIMPLEMENTED(FATAL); // this case only currently exists for ARM |
| 1478 | } |
| 1479 | |
| 1480 | void X86Assembler::Load(ManagedRegister mdest, FrameOffset src, size_t size) { |
| 1481 | X86ManagedRegister dest = mdest.AsX86(); |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 1482 | if (dest.IsNoRegister()) { |
| 1483 | CHECK_EQ(0u, size); |
| 1484 | } else if (dest.IsCpuRegister()) { |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1485 | CHECK_EQ(4u, size); |
| 1486 | movl(dest.AsCpuRegister(), Address(ESP, src)); |
Ian Rogers | 9b269d2 | 2011-09-04 14:06:05 -0700 | [diff] [blame] | 1487 | } else if (dest.IsRegisterPair()) { |
| 1488 | CHECK_EQ(8u, size); |
| 1489 | movl(dest.AsRegisterPairLow(), Address(ESP, src)); |
| 1490 | movl(dest.AsRegisterPairHigh(), Address(ESP, FrameOffset(src.Int32Value()+4))); |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 1491 | } else if (dest.IsX87Register()) { |
| 1492 | if (size == 4) { |
| 1493 | flds(Address(ESP, src)); |
| 1494 | } else { |
| 1495 | fldl(Address(ESP, src)); |
| 1496 | } |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1497 | } else { |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 1498 | CHECK(dest.IsXmmRegister()); |
| 1499 | if (size == 4) { |
| 1500 | movss(dest.AsXmmRegister(), Address(ESP, src)); |
| 1501 | } else { |
| 1502 | movsd(dest.AsXmmRegister(), Address(ESP, src)); |
| 1503 | } |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame^] | 1507 | void X86Assembler::Load(ManagedRegister mdest, ThreadOffset src, size_t size) { |
| 1508 | X86ManagedRegister dest = mdest.AsX86(); |
| 1509 | if (dest.IsNoRegister()) { |
| 1510 | CHECK_EQ(0u, size); |
| 1511 | } else if (dest.IsCpuRegister()) { |
| 1512 | CHECK_EQ(4u, size); |
| 1513 | fs()->movl(dest.AsCpuRegister(), Address::Absolute(src)); |
| 1514 | } else if (dest.IsRegisterPair()) { |
| 1515 | CHECK_EQ(8u, size); |
| 1516 | fs()->movl(dest.AsRegisterPairLow(), Address::Absolute(src)); |
| 1517 | fs()->movl(dest.AsRegisterPairHigh(), Address::Absolute(ThreadOffset(src.Int32Value()+4))); |
| 1518 | } else if (dest.IsX87Register()) { |
| 1519 | if (size == 4) { |
| 1520 | fs()->flds(Address::Absolute(src)); |
| 1521 | } else { |
| 1522 | fs()->fldl(Address::Absolute(src)); |
| 1523 | } |
| 1524 | } else { |
| 1525 | CHECK(dest.IsXmmRegister()); |
| 1526 | if (size == 4) { |
| 1527 | fs()->movss(dest.AsXmmRegister(), Address::Absolute(src)); |
| 1528 | } else { |
| 1529 | fs()->movsd(dest.AsXmmRegister(), Address::Absolute(src)); |
| 1530 | } |
| 1531 | } |
| 1532 | } |
| 1533 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1534 | void X86Assembler::LoadRef(ManagedRegister mdest, FrameOffset src) { |
| 1535 | X86ManagedRegister dest = mdest.AsX86(); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1536 | CHECK(dest.IsCpuRegister()); |
| 1537 | movl(dest.AsCpuRegister(), Address(ESP, src)); |
| 1538 | } |
| 1539 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1540 | void X86Assembler::LoadRef(ManagedRegister mdest, ManagedRegister base, |
| 1541 | MemberOffset offs) { |
| 1542 | X86ManagedRegister dest = mdest.AsX86(); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1543 | CHECK(dest.IsCpuRegister() && dest.IsCpuRegister()); |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1544 | movl(dest.AsCpuRegister(), Address(base.AsX86().AsCpuRegister(), offs)); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1547 | void X86Assembler::LoadRawPtr(ManagedRegister mdest, ManagedRegister base, |
| 1548 | Offset offs) { |
| 1549 | X86ManagedRegister dest = mdest.AsX86(); |
Ian Rogers | a04d397 | 2011-08-17 11:33:44 -0700 | [diff] [blame] | 1550 | CHECK(dest.IsCpuRegister() && dest.IsCpuRegister()); |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1551 | movl(dest.AsCpuRegister(), Address(base.AsX86().AsCpuRegister(), offs)); |
Ian Rogers | a04d397 | 2011-08-17 11:33:44 -0700 | [diff] [blame] | 1552 | } |
| 1553 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1554 | void X86Assembler::LoadRawPtrFromThread(ManagedRegister mdest, |
| 1555 | ThreadOffset offs) { |
| 1556 | X86ManagedRegister dest = mdest.AsX86(); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1557 | CHECK(dest.IsCpuRegister()); |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 1558 | fs()->movl(dest.AsCpuRegister(), Address::Absolute(offs)); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1559 | } |
| 1560 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1561 | void X86Assembler::Move(ManagedRegister mdest, ManagedRegister msrc) { |
| 1562 | X86ManagedRegister dest = mdest.AsX86(); |
| 1563 | X86ManagedRegister src = msrc.AsX86(); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1564 | if (!dest.Equals(src)) { |
| 1565 | if (dest.IsCpuRegister() && src.IsCpuRegister()) { |
| 1566 | movl(dest.AsCpuRegister(), src.AsCpuRegister()); |
| 1567 | } else { |
| 1568 | // TODO: x87, SSE |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1569 | UNIMPLEMENTED(FATAL) << ": Move " << dest << ", " << src; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1570 | } |
| 1571 | } |
| 1572 | } |
| 1573 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1574 | void X86Assembler::CopyRef(FrameOffset dest, FrameOffset src, |
| 1575 | ManagedRegister mscratch) { |
| 1576 | X86ManagedRegister scratch = mscratch.AsX86(); |
| 1577 | CHECK(scratch.IsCpuRegister()); |
| 1578 | movl(scratch.AsCpuRegister(), Address(ESP, src)); |
| 1579 | movl(Address(ESP, dest), scratch.AsCpuRegister()); |
| 1580 | } |
| 1581 | |
| 1582 | void X86Assembler::CopyRawPtrFromThread(FrameOffset fr_offs, |
| 1583 | ThreadOffset thr_offs, |
| 1584 | ManagedRegister mscratch) { |
| 1585 | X86ManagedRegister scratch = mscratch.AsX86(); |
| 1586 | CHECK(scratch.IsCpuRegister()); |
| 1587 | fs()->movl(scratch.AsCpuRegister(), Address::Absolute(thr_offs)); |
| 1588 | Store(fr_offs, scratch, 4); |
| 1589 | } |
| 1590 | |
| 1591 | void X86Assembler::CopyRawPtrToThread(ThreadOffset thr_offs, |
| 1592 | FrameOffset fr_offs, |
| 1593 | ManagedRegister mscratch) { |
| 1594 | X86ManagedRegister scratch = mscratch.AsX86(); |
| 1595 | CHECK(scratch.IsCpuRegister()); |
| 1596 | Load(scratch, fr_offs, 4); |
| 1597 | fs()->movl(Address::Absolute(thr_offs), scratch.AsCpuRegister()); |
| 1598 | } |
| 1599 | |
| 1600 | void X86Assembler::Copy(FrameOffset dest, FrameOffset src, |
| 1601 | ManagedRegister mscratch, |
| 1602 | size_t size) { |
| 1603 | X86ManagedRegister scratch = mscratch.AsX86(); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1604 | if (scratch.IsCpuRegister() && size == 8) { |
| 1605 | Load(scratch, src, 4); |
| 1606 | Store(dest, scratch, 4); |
| 1607 | Load(scratch, FrameOffset(src.Int32Value() + 4), 4); |
| 1608 | Store(FrameOffset(dest.Int32Value() + 4), scratch, 4); |
| 1609 | } else { |
| 1610 | Load(scratch, src, size); |
| 1611 | Store(dest, scratch, size); |
| 1612 | } |
| 1613 | } |
| 1614 | |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 1615 | void X86Assembler::Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset, |
| 1616 | ManagedRegister scratch, size_t size) { |
| 1617 | UNIMPLEMENTED(FATAL); |
| 1618 | } |
| 1619 | |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame^] | 1620 | void X86Assembler::Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src, |
| 1621 | ManagedRegister scratch, size_t size) { |
| 1622 | CHECK(scratch.IsNoRegister()); |
| 1623 | CHECK_EQ(size, 4u); |
| 1624 | pushl(Address(ESP, src)); |
| 1625 | popl(Address(dest_base.AsX86().AsCpuRegister(), dest_offset)); |
| 1626 | } |
| 1627 | |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 1628 | void X86Assembler::Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset, |
| 1629 | ManagedRegister mscratch, size_t size) { |
| 1630 | Register scratch = mscratch.AsX86().AsCpuRegister(); |
| 1631 | CHECK_EQ(size, 4u); |
| 1632 | movl(scratch, Address(ESP, src_base)); |
| 1633 | movl(scratch, Address(scratch, src_offset)); |
| 1634 | movl(Address(ESP, dest), scratch); |
| 1635 | } |
| 1636 | |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame^] | 1637 | void X86Assembler::Copy(ManagedRegister dest, Offset dest_offset, |
| 1638 | ManagedRegister src, Offset src_offset, |
| 1639 | ManagedRegister scratch, size_t size) { |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 1640 | CHECK_EQ(size, 4u); |
Ian Rogers | 5a7a74a | 2011-09-26 16:32:29 -0700 | [diff] [blame^] | 1641 | CHECK(scratch.IsNoRegister()); |
| 1642 | pushl(Address(src.AsX86().AsCpuRegister(), src_offset)); |
| 1643 | popl(Address(dest.AsX86().AsCpuRegister(), dest_offset)); |
| 1644 | } |
| 1645 | |
| 1646 | void X86Assembler::Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset, |
| 1647 | ManagedRegister mscratch, size_t size) { |
| 1648 | Register scratch = mscratch.AsX86().AsCpuRegister(); |
| 1649 | CHECK_EQ(size, 4u); |
| 1650 | CHECK_EQ(dest.Int32Value(), src.Int32Value()); |
| 1651 | movl(scratch, Address(ESP, src)); |
| 1652 | pushl(Address(scratch, src_offset)); |
Ian Rogers | dc51b79 | 2011-09-22 20:41:37 -0700 | [diff] [blame] | 1653 | popl(Address(scratch, dest_offset)); |
| 1654 | } |
| 1655 | |
Ian Rogers | e5de95b | 2011-09-18 20:31:38 -0700 | [diff] [blame] | 1656 | void X86Assembler::MemoryBarrier(ManagedRegister) { |
| 1657 | #if ANDROID_SMP != 0 |
| 1658 | EmitUint8(0x0F); // mfence |
| 1659 | EmitUint8(0xAE); |
Ian Rogers | e007b10 | 2011-09-19 09:47:09 -0700 | [diff] [blame] | 1660 | EmitUint8(0xF0); |
Ian Rogers | e5de95b | 2011-09-18 20:31:38 -0700 | [diff] [blame] | 1661 | #endif |
| 1662 | } |
| 1663 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1664 | void X86Assembler::CreateSirtEntry(ManagedRegister mout_reg, |
| 1665 | FrameOffset sirt_offset, |
| 1666 | ManagedRegister min_reg, bool null_allowed) { |
| 1667 | X86ManagedRegister out_reg = mout_reg.AsX86(); |
| 1668 | X86ManagedRegister in_reg = min_reg.AsX86(); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1669 | CHECK(in_reg.IsCpuRegister()); |
| 1670 | CHECK(out_reg.IsCpuRegister()); |
Ian Rogers | 408f79a | 2011-08-23 18:22:33 -0700 | [diff] [blame] | 1671 | VerifyObject(in_reg, null_allowed); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1672 | if (null_allowed) { |
| 1673 | Label null_arg; |
| 1674 | if (!out_reg.Equals(in_reg)) { |
| 1675 | xorl(out_reg.AsCpuRegister(), out_reg.AsCpuRegister()); |
| 1676 | } |
| 1677 | testl(in_reg.AsCpuRegister(), in_reg.AsCpuRegister()); |
Elliott Hughes | 18c0753 | 2011-08-18 15:50:51 -0700 | [diff] [blame] | 1678 | j(kZero, &null_arg); |
Ian Rogers | 408f79a | 2011-08-23 18:22:33 -0700 | [diff] [blame] | 1679 | leal(out_reg.AsCpuRegister(), Address(ESP, sirt_offset)); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1680 | Bind(&null_arg); |
| 1681 | } else { |
Ian Rogers | 408f79a | 2011-08-23 18:22:33 -0700 | [diff] [blame] | 1682 | leal(out_reg.AsCpuRegister(), Address(ESP, sirt_offset)); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1683 | } |
| 1684 | } |
| 1685 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1686 | void X86Assembler::CreateSirtEntry(FrameOffset out_off, |
| 1687 | FrameOffset sirt_offset, |
| 1688 | ManagedRegister mscratch, |
| 1689 | bool null_allowed) { |
| 1690 | X86ManagedRegister scratch = mscratch.AsX86(); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1691 | CHECK(scratch.IsCpuRegister()); |
| 1692 | if (null_allowed) { |
| 1693 | Label null_arg; |
Ian Rogers | 408f79a | 2011-08-23 18:22:33 -0700 | [diff] [blame] | 1694 | movl(scratch.AsCpuRegister(), Address(ESP, sirt_offset)); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1695 | testl(scratch.AsCpuRegister(), scratch.AsCpuRegister()); |
Elliott Hughes | 18c0753 | 2011-08-18 15:50:51 -0700 | [diff] [blame] | 1696 | j(kZero, &null_arg); |
Ian Rogers | 408f79a | 2011-08-23 18:22:33 -0700 | [diff] [blame] | 1697 | leal(scratch.AsCpuRegister(), Address(ESP, sirt_offset)); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1698 | Bind(&null_arg); |
| 1699 | } else { |
Ian Rogers | 408f79a | 2011-08-23 18:22:33 -0700 | [diff] [blame] | 1700 | leal(scratch.AsCpuRegister(), Address(ESP, sirt_offset)); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1701 | } |
| 1702 | Store(out_off, scratch, 4); |
| 1703 | } |
| 1704 | |
Ian Rogers | 408f79a | 2011-08-23 18:22:33 -0700 | [diff] [blame] | 1705 | // Given a SIRT entry, load the associated reference. |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1706 | void X86Assembler::LoadReferenceFromSirt(ManagedRegister mout_reg, |
| 1707 | ManagedRegister min_reg) { |
| 1708 | X86ManagedRegister out_reg = mout_reg.AsX86(); |
| 1709 | X86ManagedRegister in_reg = min_reg.AsX86(); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1710 | CHECK(out_reg.IsCpuRegister()); |
| 1711 | CHECK(in_reg.IsCpuRegister()); |
| 1712 | Label null_arg; |
| 1713 | if (!out_reg.Equals(in_reg)) { |
| 1714 | xorl(out_reg.AsCpuRegister(), out_reg.AsCpuRegister()); |
| 1715 | } |
| 1716 | testl(in_reg.AsCpuRegister(), in_reg.AsCpuRegister()); |
Elliott Hughes | 18c0753 | 2011-08-18 15:50:51 -0700 | [diff] [blame] | 1717 | j(kZero, &null_arg); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1718 | movl(out_reg.AsCpuRegister(), Address(in_reg.AsCpuRegister(), 0)); |
| 1719 | Bind(&null_arg); |
| 1720 | } |
| 1721 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1722 | void X86Assembler::VerifyObject(ManagedRegister src, bool could_be_null) { |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1723 | // TODO: not validating references |
| 1724 | } |
| 1725 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1726 | void X86Assembler::VerifyObject(FrameOffset src, bool could_be_null) { |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1727 | // TODO: not validating references |
| 1728 | } |
| 1729 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1730 | void X86Assembler::Call(ManagedRegister mbase, Offset offset, ManagedRegister) { |
| 1731 | X86ManagedRegister base = mbase.AsX86(); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1732 | CHECK(base.IsCpuRegister()); |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 1733 | call(Address(base.AsCpuRegister(), offset.Int32Value())); |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1734 | // TODO: place reference map on call |
| 1735 | } |
| 1736 | |
Ian Rogers | 67375ac | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 1737 | void X86Assembler::Call(FrameOffset base, Offset offset, ManagedRegister mscratch) { |
| 1738 | Register scratch = mscratch.AsX86().AsCpuRegister(); |
| 1739 | movl(scratch, Address(ESP, base)); |
| 1740 | call(Address(scratch, offset)); |
Carl Shapiro | e2d373e | 2011-07-25 15:20:06 -0700 | [diff] [blame] | 1741 | } |
| 1742 | |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 1743 | void X86Assembler::Call(ThreadOffset offset, ManagedRegister mscratch) { |
| 1744 | fs()->call(Address::Absolute(offset)); |
Shih-wei Liao | 668512a | 2011-09-01 14:18:34 -0700 | [diff] [blame] | 1745 | } |
| 1746 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1747 | void X86Assembler::GetCurrentThread(ManagedRegister tr) { |
| 1748 | fs()->movl(tr.AsX86().AsCpuRegister(), |
| 1749 | Address::Absolute(Thread::SelfOffset())); |
Shih-wei Liao | 668512a | 2011-09-01 14:18:34 -0700 | [diff] [blame] | 1750 | } |
| 1751 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1752 | void X86Assembler::GetCurrentThread(FrameOffset offset, |
| 1753 | ManagedRegister mscratch) { |
| 1754 | X86ManagedRegister scratch = mscratch.AsX86(); |
Shih-wei Liao | 668512a | 2011-09-01 14:18:34 -0700 | [diff] [blame] | 1755 | fs()->movl(scratch.AsCpuRegister(), Address::Absolute(Thread::SelfOffset())); |
| 1756 | movl(Address(ESP, offset), scratch.AsCpuRegister()); |
| 1757 | } |
| 1758 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1759 | void X86Assembler::SuspendPoll(ManagedRegister scratch, |
| 1760 | ManagedRegister return_reg, |
| 1761 | FrameOffset return_save_location, |
| 1762 | size_t return_size) { |
| 1763 | X86SuspendCountSlowPath* slow = |
| 1764 | new X86SuspendCountSlowPath(return_reg.AsX86(), return_save_location, |
| 1765 | return_size); |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 1766 | buffer_.EnqueueSlowPath(slow); |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 1767 | fs()->cmpl(Address::Absolute(Thread::SuspendCountOffset()), Immediate(0)); |
Elliott Hughes | 18c0753 | 2011-08-18 15:50:51 -0700 | [diff] [blame] | 1768 | j(kNotEqual, slow->Entry()); |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 1769 | Bind(slow->Continuation()); |
| 1770 | } |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 1771 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1772 | void X86SuspendCountSlowPath::Emit(Assembler *sasm) { |
| 1773 | X86Assembler* sp_asm = down_cast<X86Assembler*>(sasm); |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 1774 | #define __ sp_asm-> |
| 1775 | __ Bind(&entry_); |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 1776 | // Save return value |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 1777 | __ Store(return_save_location_, return_register_, return_size_); |
Ian Rogers | e5de95b | 2011-09-18 20:31:38 -0700 | [diff] [blame] | 1778 | // Pass Thread::Current as argument |
| 1779 | __ fs()->pushl(Address::Absolute(Thread::SelfOffset())); |
| 1780 | __ fs()->call(Address::Absolute(OFFSETOF_MEMBER(Thread, pCheckSuspendFromCode))); |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 1781 | // Release argument |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 1782 | __ addl(ESP, Immediate(kPointerSize)); |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 1783 | // Reload return value |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 1784 | __ Load(return_register_, return_save_location_, return_size_); |
| 1785 | __ jmp(&continuation_); |
| 1786 | #undef __ |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1789 | void X86Assembler::ExceptionPoll(ManagedRegister scratch) { |
| 1790 | X86ExceptionSlowPath* slow = new X86ExceptionSlowPath(); |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 1791 | buffer_.EnqueueSlowPath(slow); |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 1792 | fs()->cmpl(Address::Absolute(Thread::ExceptionOffset()), Immediate(0)); |
Elliott Hughes | 18c0753 | 2011-08-18 15:50:51 -0700 | [diff] [blame] | 1793 | j(kNotEqual, slow->Entry()); |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 1794 | } |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 1795 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1796 | void X86ExceptionSlowPath::Emit(Assembler *sasm) { |
| 1797 | X86Assembler* sp_asm = down_cast<X86Assembler*>(sasm); |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 1798 | #define __ sp_asm-> |
| 1799 | __ Bind(&entry_); |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 1800 | // NB the return value is dead |
Ian Rogers | 67375ac | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 1801 | // Pass exception as argument in EAX |
| 1802 | __ fs()->movl(EAX, Address::Absolute(Thread::ExceptionOffset())); |
| 1803 | __ fs()->call(Address::Absolute(OFFSETOF_MEMBER(Thread, pDeliverException))); |
| 1804 | // this call should never return |
| 1805 | __ int3(); |
Ian Rogers | 0d666d8 | 2011-08-14 16:03:46 -0700 | [diff] [blame] | 1806 | #undef __ |
Ian Rogers | 45a76cb | 2011-07-21 22:00:15 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 1809 | } // namespace x86 |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1810 | } // namespace art |