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