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