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