ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1 | // Copyright (c) 1994-2006 Sun Microsystems Inc. |
| 2 | // All Rights Reserved. |
| 3 | // |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 8 | // - Redistributions of source code must retain the above copyright notice, |
| 9 | // this list of conditions and the following disclaimer. |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 10 | // |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 11 | // - Redistribution in binary form must reproduce the above copyright |
| 12 | // notice, this list of conditions and the following disclaimer in the |
| 13 | // documentation and/or other materials provided with the distribution. |
| 14 | // |
| 15 | // - Neither the name of Sun Microsystems or the names of contributors may |
| 16 | // be used to endorse or promote products derived from this software without |
| 17 | // specific prior written permission. |
| 18 | // |
| 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 20 | // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 21 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 22 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 23 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 24 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 25 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 26 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 27 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 28 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 30 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 31 | // The original source code covered by the above license above has been |
| 32 | // modified significantly by Google Inc. |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 33 | // Copyright 2012 the V8 project authors. All rights reserved. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 34 | |
| 35 | // A lightweight X64 Assembler. |
| 36 | |
| 37 | #ifndef V8_X64_ASSEMBLER_X64_H_ |
| 38 | #define V8_X64_ASSEMBLER_X64_H_ |
| 39 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 40 | #include "serialize.h" |
| 41 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 42 | namespace v8 { |
| 43 | namespace internal { |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 44 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 45 | // Utility functions |
| 46 | |
| 47 | // Test whether a 64-bit value is in a specific range. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 48 | inline bool is_uint32(int64_t x) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 49 | static const uint64_t kMaxUInt32 = V8_UINT64_C(0xffffffff); |
| 50 | return static_cast<uint64_t>(x) <= kMaxUInt32; |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 51 | } |
| 52 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 53 | inline bool is_int32(int64_t x) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 54 | static const int64_t kMinInt32 = -V8_INT64_C(0x80000000); |
| 55 | return is_uint32(x - kMinInt32); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 56 | } |
| 57 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 58 | inline bool uint_is_int32(uint64_t x) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 59 | static const uint64_t kMaxInt32 = V8_UINT64_C(0x7fffffff); |
| 60 | return x <= kMaxInt32; |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 61 | } |
| 62 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 63 | inline bool is_uint32(uint64_t x) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 64 | static const uint64_t kMaxUInt32 = V8_UINT64_C(0xffffffff); |
| 65 | return x <= kMaxUInt32; |
sgjesse@chromium.org | b9d7da1 | 2009-08-05 08:38:10 +0000 | [diff] [blame] | 66 | } |
| 67 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 68 | // CPU Registers. |
| 69 | // |
| 70 | // 1) We would prefer to use an enum, but enum values are assignment- |
| 71 | // compatible with int, which has caused code-generation bugs. |
| 72 | // |
| 73 | // 2) We would prefer to use a class instead of a struct but we don't like |
| 74 | // the register initialization to depend on the particular initialization |
| 75 | // order (which appears to be different on OS X, Linux, and Windows for the |
| 76 | // installed versions of C++ we tried). Using a struct permits C-style |
| 77 | // "initialization". Also, the Register objects cannot be const as this |
| 78 | // forces initialization stubs in MSVC, making us dependent on initialization |
| 79 | // order. |
| 80 | // |
| 81 | // 3) By not using an enum, we are possibly preventing the compiler from |
| 82 | // doing certain constant folds, which may significantly reduce the |
| 83 | // code generated for some assembly instructions (because they boil down |
| 84 | // to a few constants). If this is a problem, we could change the code |
| 85 | // such that we use an enum in optimized mode, and the struct in debug |
| 86 | // mode. This way we get the compile-time error checking in debug mode |
| 87 | // and best performance in optimized code. |
| 88 | // |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 89 | |
| 90 | struct Register { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 91 | // The non-allocatable registers are: |
| 92 | // rsp - stack pointer |
| 93 | // rbp - frame pointer |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 94 | // r10 - fixed scratch register |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 95 | // r12 - smi constant register |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 96 | // r13 - root register |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 97 | static const int kMaxNumAllocatableRegisters = 11; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 98 | static int NumAllocatableRegisters() { |
| 99 | return kMaxNumAllocatableRegisters; |
| 100 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 101 | static const int kNumRegisters = 16; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 102 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 103 | static int ToAllocationIndex(Register reg) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 104 | return kAllocationIndexByRegisterCode[reg.code()]; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static Register FromAllocationIndex(int index) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 108 | ASSERT(index >= 0 && index < kMaxNumAllocatableRegisters); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 109 | Register result = { kRegisterCodeByAllocationIndex[index] }; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 110 | return result; |
| 111 | } |
| 112 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 113 | static const char* AllocationIndexToString(int index) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 114 | ASSERT(index >= 0 && index < kMaxNumAllocatableRegisters); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 115 | const char* const names[] = { |
| 116 | "rax", |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 117 | "rbx", |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 118 | "rdx", |
| 119 | "rcx", |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 120 | "rsi", |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 121 | "rdi", |
| 122 | "r8", |
| 123 | "r9", |
| 124 | "r11", |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 125 | "r14", |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 126 | "r15" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 127 | }; |
| 128 | return names[index]; |
| 129 | } |
| 130 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 131 | static Register from_code(int code) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 132 | Register r = { code }; |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 133 | return r; |
| 134 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 135 | bool is_valid() const { return 0 <= code_ && code_ < kNumRegisters; } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 136 | bool is(Register reg) const { return code_ == reg.code_; } |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 137 | // rax, rbx, rcx and rdx are byte registers, the rest are not. |
| 138 | bool is_byte_register() const { return code_ <= 3; } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 139 | int code() const { |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 140 | ASSERT(is_valid()); |
| 141 | return code_; |
| 142 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 143 | int bit() const { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 144 | return 1 << code_; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 145 | } |
| 146 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 147 | // Return the high bit of the register code as a 0 or 1. Used often |
| 148 | // when constructing the REX prefix byte. |
| 149 | int high_bit() const { |
| 150 | return code_ >> 3; |
| 151 | } |
| 152 | // Return the 3 low bits of the register code. Used when encoding registers |
| 153 | // in modR/M, SIB, and opcode bytes. |
| 154 | int low_bits() const { |
| 155 | return code_ & 0x7; |
| 156 | } |
| 157 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 158 | // Unfortunately we can't make this private in a struct when initializing |
| 159 | // by assignment. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 160 | int code_; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 161 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 162 | private: |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 163 | static const int kRegisterCodeByAllocationIndex[kMaxNumAllocatableRegisters]; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 164 | static const int kAllocationIndexByRegisterCode[kNumRegisters]; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 165 | }; |
| 166 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 167 | const int kRegister_rax_Code = 0; |
| 168 | const int kRegister_rcx_Code = 1; |
| 169 | const int kRegister_rdx_Code = 2; |
| 170 | const int kRegister_rbx_Code = 3; |
| 171 | const int kRegister_rsp_Code = 4; |
| 172 | const int kRegister_rbp_Code = 5; |
| 173 | const int kRegister_rsi_Code = 6; |
| 174 | const int kRegister_rdi_Code = 7; |
| 175 | const int kRegister_r8_Code = 8; |
| 176 | const int kRegister_r9_Code = 9; |
| 177 | const int kRegister_r10_Code = 10; |
| 178 | const int kRegister_r11_Code = 11; |
| 179 | const int kRegister_r12_Code = 12; |
| 180 | const int kRegister_r13_Code = 13; |
| 181 | const int kRegister_r14_Code = 14; |
| 182 | const int kRegister_r15_Code = 15; |
| 183 | const int kRegister_no_reg_Code = -1; |
| 184 | |
| 185 | const Register rax = { kRegister_rax_Code }; |
| 186 | const Register rcx = { kRegister_rcx_Code }; |
| 187 | const Register rdx = { kRegister_rdx_Code }; |
| 188 | const Register rbx = { kRegister_rbx_Code }; |
| 189 | const Register rsp = { kRegister_rsp_Code }; |
| 190 | const Register rbp = { kRegister_rbp_Code }; |
| 191 | const Register rsi = { kRegister_rsi_Code }; |
| 192 | const Register rdi = { kRegister_rdi_Code }; |
| 193 | const Register r8 = { kRegister_r8_Code }; |
| 194 | const Register r9 = { kRegister_r9_Code }; |
| 195 | const Register r10 = { kRegister_r10_Code }; |
| 196 | const Register r11 = { kRegister_r11_Code }; |
| 197 | const Register r12 = { kRegister_r12_Code }; |
| 198 | const Register r13 = { kRegister_r13_Code }; |
| 199 | const Register r14 = { kRegister_r14_Code }; |
| 200 | const Register r15 = { kRegister_r15_Code }; |
| 201 | const Register no_reg = { kRegister_no_reg_Code }; |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 202 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 203 | #ifdef _WIN64 |
| 204 | // Windows calling convention |
danno@chromium.org | 6b0169a | 2013-04-26 15:48:26 +0000 | [diff] [blame] | 205 | const Register arg_reg_1 = { kRegister_rcx_Code }; |
| 206 | const Register arg_reg_2 = { kRegister_rdx_Code }; |
| 207 | const Register arg_reg_3 = { kRegister_r8_Code }; |
| 208 | const Register arg_reg_4 = { kRegister_r9_Code }; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 209 | #else |
| 210 | // AMD64 calling convention |
danno@chromium.org | 6b0169a | 2013-04-26 15:48:26 +0000 | [diff] [blame] | 211 | const Register arg_reg_1 = { kRegister_rdi_Code }; |
| 212 | const Register arg_reg_2 = { kRegister_rsi_Code }; |
| 213 | const Register arg_reg_3 = { kRegister_rdx_Code }; |
| 214 | const Register arg_reg_4 = { kRegister_rcx_Code }; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 215 | #endif // _WIN64 |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 216 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 217 | struct XMMRegister { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 218 | static const int kMaxNumRegisters = 16; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 219 | static const int kMaxNumAllocatableRegisters = 15; |
| 220 | static int NumAllocatableRegisters() { |
| 221 | return kMaxNumAllocatableRegisters; |
| 222 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 223 | |
| 224 | static int ToAllocationIndex(XMMRegister reg) { |
| 225 | ASSERT(reg.code() != 0); |
| 226 | return reg.code() - 1; |
| 227 | } |
| 228 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 229 | static XMMRegister FromAllocationIndex(int index) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 230 | ASSERT(0 <= index && index < kMaxNumAllocatableRegisters); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 231 | XMMRegister result = { index + 1 }; |
| 232 | return result; |
| 233 | } |
| 234 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 235 | static const char* AllocationIndexToString(int index) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 236 | ASSERT(index >= 0 && index < kMaxNumAllocatableRegisters); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 237 | const char* const names[] = { |
| 238 | "xmm1", |
| 239 | "xmm2", |
| 240 | "xmm3", |
| 241 | "xmm4", |
| 242 | "xmm5", |
| 243 | "xmm6", |
| 244 | "xmm7", |
| 245 | "xmm8", |
| 246 | "xmm9", |
| 247 | "xmm10", |
| 248 | "xmm11", |
| 249 | "xmm12", |
| 250 | "xmm13", |
| 251 | "xmm14", |
| 252 | "xmm15" |
| 253 | }; |
| 254 | return names[index]; |
| 255 | } |
| 256 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 257 | static XMMRegister from_code(int code) { |
| 258 | ASSERT(code >= 0); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 259 | ASSERT(code < kMaxNumRegisters); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 260 | XMMRegister r = { code }; |
| 261 | return r; |
| 262 | } |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 263 | bool is_valid() const { return 0 <= code_ && code_ < kMaxNumRegisters; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 264 | bool is(XMMRegister reg) const { return code_ == reg.code_; } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 265 | int code() const { |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 266 | ASSERT(is_valid()); |
| 267 | return code_; |
| 268 | } |
| 269 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 270 | // Return the high bit of the register code as a 0 or 1. Used often |
| 271 | // when constructing the REX prefix byte. |
| 272 | int high_bit() const { |
| 273 | return code_ >> 3; |
| 274 | } |
| 275 | // Return the 3 low bits of the register code. Used when encoding registers |
| 276 | // in modR/M, SIB, and opcode bytes. |
| 277 | int low_bits() const { |
| 278 | return code_ & 0x7; |
| 279 | } |
| 280 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 281 | int code_; |
| 282 | }; |
| 283 | |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 284 | const XMMRegister xmm0 = { 0 }; |
| 285 | const XMMRegister xmm1 = { 1 }; |
| 286 | const XMMRegister xmm2 = { 2 }; |
| 287 | const XMMRegister xmm3 = { 3 }; |
| 288 | const XMMRegister xmm4 = { 4 }; |
| 289 | const XMMRegister xmm5 = { 5 }; |
| 290 | const XMMRegister xmm6 = { 6 }; |
| 291 | const XMMRegister xmm7 = { 7 }; |
| 292 | const XMMRegister xmm8 = { 8 }; |
| 293 | const XMMRegister xmm9 = { 9 }; |
| 294 | const XMMRegister xmm10 = { 10 }; |
| 295 | const XMMRegister xmm11 = { 11 }; |
| 296 | const XMMRegister xmm12 = { 12 }; |
| 297 | const XMMRegister xmm13 = { 13 }; |
| 298 | const XMMRegister xmm14 = { 14 }; |
| 299 | const XMMRegister xmm15 = { 15 }; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 300 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 301 | |
| 302 | typedef XMMRegister DoubleRegister; |
| 303 | |
| 304 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 305 | enum Condition { |
| 306 | // any value < 0 is considered no_condition |
| 307 | no_condition = -1, |
| 308 | |
| 309 | overflow = 0, |
| 310 | no_overflow = 1, |
| 311 | below = 2, |
| 312 | above_equal = 3, |
| 313 | equal = 4, |
| 314 | not_equal = 5, |
| 315 | below_equal = 6, |
| 316 | above = 7, |
| 317 | negative = 8, |
| 318 | positive = 9, |
| 319 | parity_even = 10, |
| 320 | parity_odd = 11, |
| 321 | less = 12, |
| 322 | greater_equal = 13, |
| 323 | less_equal = 14, |
| 324 | greater = 15, |
| 325 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 326 | // Fake conditions that are handled by the |
| 327 | // opcodes using them. |
| 328 | always = 16, |
| 329 | never = 17, |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 330 | // aliases |
| 331 | carry = below, |
| 332 | not_carry = above_equal, |
| 333 | zero = equal, |
| 334 | not_zero = not_equal, |
| 335 | sign = negative, |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 336 | not_sign = positive, |
| 337 | last_condition = greater |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 338 | }; |
| 339 | |
| 340 | |
| 341 | // Returns the equivalent of !cc. |
| 342 | // Negation of the default no_condition (-1) results in a non-default |
| 343 | // no_condition value (-2). As long as tests for no_condition check |
| 344 | // for condition < 0, this will work as expected. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 345 | inline Condition NegateCondition(Condition cc) { |
| 346 | return static_cast<Condition>(cc ^ 1); |
| 347 | } |
| 348 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 349 | |
| 350 | // Corresponds to transposing the operands of a comparison. |
| 351 | inline Condition ReverseCondition(Condition cc) { |
| 352 | switch (cc) { |
| 353 | case below: |
| 354 | return above; |
| 355 | case above: |
| 356 | return below; |
| 357 | case above_equal: |
| 358 | return below_equal; |
| 359 | case below_equal: |
| 360 | return above_equal; |
| 361 | case less: |
| 362 | return greater; |
| 363 | case greater: |
| 364 | return less; |
| 365 | case greater_equal: |
| 366 | return less_equal; |
| 367 | case less_equal: |
| 368 | return greater_equal; |
| 369 | default: |
| 370 | return cc; |
| 371 | }; |
| 372 | } |
| 373 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 374 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 375 | // ----------------------------------------------------------------------------- |
| 376 | // Machine instruction Immediates |
| 377 | |
| 378 | class Immediate BASE_EMBEDDED { |
| 379 | public: |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 380 | explicit Immediate(int32_t value) : value_(value) {} |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 381 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 382 | private: |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 383 | int32_t value_; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 384 | |
| 385 | friend class Assembler; |
| 386 | }; |
| 387 | |
| 388 | |
| 389 | // ----------------------------------------------------------------------------- |
| 390 | // Machine instruction Operands |
| 391 | |
| 392 | enum ScaleFactor { |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 393 | times_1 = 0, |
| 394 | times_2 = 1, |
| 395 | times_4 = 2, |
| 396 | times_8 = 3, |
| 397 | times_int_size = times_4, |
| 398 | times_pointer_size = times_8 |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 399 | }; |
| 400 | |
| 401 | |
| 402 | class Operand BASE_EMBEDDED { |
| 403 | public: |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 404 | // [base + disp/r] |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 405 | Operand(Register base, int32_t disp); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 406 | |
| 407 | // [base + index*scale + disp/r] |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 408 | Operand(Register base, |
| 409 | Register index, |
| 410 | ScaleFactor scale, |
| 411 | int32_t disp); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 412 | |
| 413 | // [index*scale + disp/r] |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 414 | Operand(Register index, |
| 415 | ScaleFactor scale, |
| 416 | int32_t disp); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 417 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 418 | // Offset from existing memory operand. |
| 419 | // Offset is added to existing displacement as 32-bit signed values and |
| 420 | // this must not overflow. |
| 421 | Operand(const Operand& base, int32_t offset); |
| 422 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 423 | // Checks whether either base or index register is the given register. |
| 424 | // Does not check the "reg" part of the Operand. |
| 425 | bool AddressUsesRegister(Register reg) const; |
| 426 | |
ricow@chromium.org | eb96f4f | 2011-03-09 13:41:48 +0000 | [diff] [blame] | 427 | // Queries related to the size of the generated instruction. |
| 428 | // Whether the generated instruction will have a REX prefix. |
| 429 | bool requires_rex() const { return rex_ != 0; } |
| 430 | // Size of the ModR/M, SIB and displacement parts of the generated |
| 431 | // instruction. |
| 432 | int operand_size() const { return len_; } |
| 433 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 434 | private: |
| 435 | byte rex_; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 436 | byte buf_[6]; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 437 | // The number of bytes of buf_ in use. |
| 438 | byte len_; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 439 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 440 | // Set the ModR/M byte without an encoded 'reg' register. The |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 441 | // register is encoded later as part of the emit_operand operation. |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 442 | // set_modrm can be called before or after set_sib and set_disp*. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 443 | inline void set_modrm(int mod, Register rm); |
| 444 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 445 | // Set the SIB byte if one is needed. Sets the length to 2 rather than 1. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 446 | inline void set_sib(ScaleFactor scale, Register index, Register base); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 447 | |
| 448 | // Adds operand displacement fields (offsets added to the memory address). |
| 449 | // Needs to be called after set_sib, not before it. |
| 450 | inline void set_disp8(int disp); |
| 451 | inline void set_disp32(int disp); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 452 | |
| 453 | friend class Assembler; |
| 454 | }; |
| 455 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 456 | |
| 457 | // CpuFeatures keeps track of which features are supported by the target CPU. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 458 | // Supported features must be enabled by a CpuFeatureScope before use. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 459 | // Example: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 460 | // if (assembler->IsSupported(SSE3)) { |
| 461 | // CpuFeatureScope fscope(assembler, SSE3); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 462 | // // Generate SSE3 floating point code. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 463 | // } else { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 464 | // // Generate standard SSE2 floating point code. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 465 | // } |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 466 | class CpuFeatures : public AllStatic { |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 467 | public: |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 468 | // Detect features of the target CPU. Set safe defaults if the serializer |
| 469 | // is enabled (snapshots must be portable). |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 470 | static void Probe(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 471 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 472 | // Check whether a feature is supported by the target CPU. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 473 | static bool IsSupported(CpuFeature f) { |
mvstanton@chromium.org | 63ea3d2 | 2013-10-10 09:24:12 +0000 | [diff] [blame] | 474 | if (Check(f, cross_compile_)) return true; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 475 | ASSERT(initialized_); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 476 | if (f == SSE3 && !FLAG_enable_sse3) return false; |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 477 | if (f == SSE4_1 && !FLAG_enable_sse4_1) return false; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 478 | if (f == CMOV && !FLAG_enable_cmov) return false; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 479 | if (f == SAHF && !FLAG_enable_sahf) return false; |
mvstanton@chromium.org | 63ea3d2 | 2013-10-10 09:24:12 +0000 | [diff] [blame] | 480 | return Check(f, supported_); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 481 | } |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 482 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 483 | static bool IsFoundByRuntimeProbingOnly(CpuFeature f) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 484 | ASSERT(initialized_); |
mvstanton@chromium.org | 63ea3d2 | 2013-10-10 09:24:12 +0000 | [diff] [blame] | 485 | return Check(f, found_by_runtime_probing_only_); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 486 | } |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 487 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 488 | static bool IsSafeForSnapshot(CpuFeature f) { |
mvstanton@chromium.org | 63ea3d2 | 2013-10-10 09:24:12 +0000 | [diff] [blame] | 489 | return Check(f, cross_compile_) || |
| 490 | (IsSupported(f) && |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 491 | (!Serializer::enabled() || !IsFoundByRuntimeProbingOnly(f))); |
| 492 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 493 | |
mvstanton@chromium.org | 63ea3d2 | 2013-10-10 09:24:12 +0000 | [diff] [blame] | 494 | static bool VerifyCrossCompiling() { |
| 495 | return cross_compile_ == 0; |
| 496 | } |
| 497 | |
| 498 | static bool VerifyCrossCompiling(CpuFeature f) { |
| 499 | uint64_t mask = flag2set(f); |
| 500 | return cross_compile_ == 0 || |
| 501 | (cross_compile_ & mask) == mask; |
| 502 | } |
| 503 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 504 | private: |
mvstanton@chromium.org | 63ea3d2 | 2013-10-10 09:24:12 +0000 | [diff] [blame] | 505 | static bool Check(CpuFeature f, uint64_t set) { |
| 506 | return (set & flag2set(f)) != 0; |
| 507 | } |
| 508 | |
| 509 | static uint64_t flag2set(CpuFeature f) { |
| 510 | return static_cast<uint64_t>(1) << f; |
| 511 | } |
| 512 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 513 | // Safe defaults include CMOV for X64. It is always available, if |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 514 | // anyone checks, but they shouldn't need to check. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 515 | // The required user mode extensions in X64 are (from AMD64 ABI Table A.1): |
| 516 | // fpu, tsc, cx8, cmov, mmx, sse, sse2, fxsr, syscall |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 517 | static const uint64_t kDefaultCpuFeatures = (1 << CMOV); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 518 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 519 | #ifdef DEBUG |
| 520 | static bool initialized_; |
| 521 | #endif |
| 522 | static uint64_t supported_; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 523 | static uint64_t found_by_runtime_probing_only_; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 524 | |
mvstanton@chromium.org | 63ea3d2 | 2013-10-10 09:24:12 +0000 | [diff] [blame] | 525 | static uint64_t cross_compile_; |
| 526 | |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 527 | friend class ExternalReference; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 528 | friend class PlatformFeatureScope; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 529 | DISALLOW_COPY_AND_ASSIGN(CpuFeatures); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 530 | }; |
| 531 | |
| 532 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 533 | class Assembler : public AssemblerBase { |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 534 | private: |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 535 | // We check before assembling an instruction that there is sufficient |
| 536 | // space to write an instruction and its relocation information. |
| 537 | // The relocation writer's position must be kGap bytes above the end of |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 538 | // the generated instructions. This leaves enough space for the |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 539 | // longest possible x64 instruction, 15 bytes, and the longest possible |
| 540 | // relocation information encoding, RelocInfoWriter::kMaxLength == 16. |
| 541 | // (There is a 15 byte limit on x64 instruction length that rules out some |
| 542 | // otherwise valid instructions.) |
| 543 | // This allows for a single, fast space check per instruction. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 544 | static const int kGap = 32; |
| 545 | |
| 546 | public: |
| 547 | // Create an assembler. Instructions and relocation information are emitted |
| 548 | // into a buffer, with the instructions starting from the beginning and the |
| 549 | // relocation information starting from the end of the buffer. See CodeDesc |
| 550 | // for a detailed comment on the layout (globals.h). |
| 551 | // |
| 552 | // If the provided buffer is NULL, the assembler allocates and grows its own |
| 553 | // buffer, and buffer_size determines the initial buffer size. The buffer is |
| 554 | // owned by the assembler and deallocated upon destruction of the assembler. |
| 555 | // |
| 556 | // If the provided buffer is not NULL, the assembler uses the provided buffer |
| 557 | // for code generation and assumes its size to be buffer_size. If the buffer |
| 558 | // is too small, a fatal error occurs. No deallocation of the buffer is done |
| 559 | // upon destruction of the assembler. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 560 | Assembler(Isolate* isolate, void* buffer, int buffer_size); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 561 | virtual ~Assembler() { } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 562 | |
| 563 | // GetCode emits any pending (non-emitted) code and fills the descriptor |
| 564 | // desc. GetCode() is idempotent; it returns the same result if no other |
| 565 | // Assembler functions are invoked in between GetCode() calls. |
| 566 | void GetCode(CodeDesc* desc); |
| 567 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 568 | // Read/Modify the code target in the relative branch/call instruction at pc. |
| 569 | // On the x64 architecture, we use relative jumps with a 32-bit displacement |
| 570 | // to jump to other Code objects in the Code space in the heap. |
| 571 | // Jumps to C functions are done indirectly through a 64-bit register holding |
| 572 | // the absolute address of the target. |
| 573 | // These functions convert between absolute Addresses of Code objects and |
| 574 | // the relative displacements stored in the code. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 575 | static inline Address target_address_at(Address pc); |
| 576 | static inline void set_target_address_at(Address pc, Address target); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 577 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 578 | // Return the code target address at a call site from the return address |
| 579 | // of that call in the instruction stream. |
| 580 | static inline Address target_address_from_return_address(Address pc); |
| 581 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 582 | // This sets the branch destination (which is in the instruction on x64). |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 583 | // This is for calls and branches within generated code. |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 584 | inline static void deserialization_set_special_target_at( |
| 585 | Address instruction_payload, Address target) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 586 | set_target_address_at(instruction_payload, target); |
| 587 | } |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 588 | |
| 589 | // This sets the branch destination (which is a load instruction on x64). |
| 590 | // This is for calls and branches to runtime code. |
| 591 | inline static void set_external_target_at(Address instruction_payload, |
| 592 | Address target) { |
| 593 | *reinterpret_cast<Address*>(instruction_payload) = target; |
| 594 | } |
| 595 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 596 | inline Handle<Object> code_target_object_handle_at(Address pc); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 597 | inline Address runtime_entry_at(Address pc); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 598 | // Number of bytes taken up by the branch target in the code. |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 599 | static const int kSpecialTargetSize = 4; // Use 32-bit displacement. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 600 | // Distance between the address of the code target in the call instruction |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 601 | // and the return address pushed on the stack. |
| 602 | static const int kCallTargetAddressOffset = 4; // Use 32-bit displacement. |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 603 | // The length of call(kScratchRegister). |
| 604 | static const int kCallScratchRegisterInstructionLength = 3; |
| 605 | // The length of call(Immediate32). |
danno@chromium.org | abafe3d | 2013-08-09 20:02:11 +0000 | [diff] [blame] | 606 | static const int kShortCallInstructionLength = 5; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 607 | // The length of movq(kScratchRegister, address). |
| 608 | static const int kMoveAddressIntoScratchRegisterInstructionLength = |
| 609 | 2 + kPointerSize; |
| 610 | // The length of movq(kScratchRegister, address) and call(kScratchRegister). |
| 611 | static const int kCallSequenceLength = |
| 612 | kMoveAddressIntoScratchRegisterInstructionLength + |
| 613 | kCallScratchRegisterInstructionLength; |
danno@chromium.org | abafe3d | 2013-08-09 20:02:11 +0000 | [diff] [blame] | 614 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 615 | // The js return and debug break slot must be able to contain an indirect |
| 616 | // call sequence, some x64 JS code is padded with int3 to make it large |
| 617 | // enough to hold an instruction when the debugger patches it. |
| 618 | static const int kJSReturnSequenceLength = kCallSequenceLength; |
| 619 | static const int kDebugBreakSlotLength = kCallSequenceLength; |
| 620 | static const int kPatchDebugBreakSlotReturnOffset = kCallTargetAddressOffset; |
| 621 | // Distance between the start of the JS return sequence and where the |
| 622 | // 32-bit displacement of a short call would be. The short call is from |
| 623 | // SetDebugBreakAtIC from debug-x64.cc. |
| 624 | static const int kPatchReturnSequenceAddressOffset = |
| 625 | kJSReturnSequenceLength - kPatchDebugBreakSlotReturnOffset; |
| 626 | // Distance between the start of the JS return sequence and where the |
| 627 | // 32-bit displacement of a short call would be. The short call is from |
| 628 | // SetDebugBreakAtIC from debug-x64.cc. |
| 629 | static const int kPatchDebugBreakSlotAddressOffset = |
| 630 | kDebugBreakSlotLength - kPatchDebugBreakSlotReturnOffset; |
| 631 | static const int kRealPatchReturnSequenceAddressOffset = |
| 632 | kMoveAddressIntoScratchRegisterInstructionLength - kPointerSize; |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 633 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 634 | // One byte opcode for test eax,0xXXXXXXXX. |
| 635 | static const byte kTestEaxByte = 0xA9; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 636 | // One byte opcode for test al, 0xXX. |
| 637 | static const byte kTestAlByte = 0xA8; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 638 | // One byte opcode for nop. |
| 639 | static const byte kNopByte = 0x90; |
| 640 | |
| 641 | // One byte prefix for a short conditional jump. |
| 642 | static const byte kJccShortPrefix = 0x70; |
| 643 | static const byte kJncShortOpcode = kJccShortPrefix | not_carry; |
| 644 | static const byte kJcShortOpcode = kJccShortPrefix | carry; |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 645 | static const byte kJnzShortOpcode = kJccShortPrefix | not_zero; |
| 646 | static const byte kJzShortOpcode = kJccShortPrefix | zero; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 647 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 648 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 649 | // --------------------------------------------------------------------------- |
| 650 | // Code generation |
| 651 | // |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 652 | // Function names correspond one-to-one to x64 instruction mnemonics. |
| 653 | // Unless specified otherwise, instructions operate on 64-bit operands. |
| 654 | // |
| 655 | // If we need versions of an assembly instruction that operate on different |
| 656 | // width arguments, we add a single-letter suffix specifying the width. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 657 | // This is done for the following instructions: mov, cmp, inc, dec, |
| 658 | // add, sub, and test. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 659 | // There are no versions of these instructions without the suffix. |
| 660 | // - Instructions on 8-bit (byte) operands/registers have a trailing 'b'. |
| 661 | // - Instructions on 16-bit (word) operands/registers have a trailing 'w'. |
| 662 | // - Instructions on 32-bit (doubleword) operands/registers use 'l'. |
| 663 | // - Instructions on 64-bit (quadword) operands/registers use 'q'. |
| 664 | // |
| 665 | // Some mnemonics, such as "and", are the same as C++ keywords. |
| 666 | // Naming conflicts with C++ keywords are resolved by adding a trailing '_'. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 667 | |
| 668 | // Insert the smallest number of nop instructions |
| 669 | // possible to align the pc offset to a multiple |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 670 | // of m, where m must be a power of 2. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 671 | void Align(int m); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 672 | void Nop(int bytes = 1); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 673 | // Aligns code to something that's optimal for a jump target for the platform. |
| 674 | void CodeTargetAlign(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 675 | |
| 676 | // Stack |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 677 | void pushfq(); |
| 678 | void popfq(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 679 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 680 | void push(Immediate value); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 681 | // Push a 32 bit integer, and guarantee that it is actually pushed as a |
| 682 | // 32 bit value, the normal push will optimize the 8 bit case. |
| 683 | void push_imm32(int32_t imm32); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 684 | void push(Register src); |
| 685 | void push(const Operand& src); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 686 | |
| 687 | void pop(Register dst); |
| 688 | void pop(const Operand& dst); |
| 689 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 690 | void enter(Immediate size); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 691 | void leave(); |
| 692 | |
| 693 | // Moves |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 694 | void movb(Register dst, const Operand& src); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 695 | void movb(Register dst, Immediate imm); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 696 | void movb(const Operand& dst, Register src); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 697 | void movb(const Operand& dst, Immediate imm); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 698 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 699 | // Move the low 16 bits of a 64-bit register value to a 16-bit |
| 700 | // memory location. |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 701 | void movw(Register dst, const Operand& src); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 702 | void movw(const Operand& dst, Register src); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 703 | void movw(const Operand& dst, Immediate imm); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 704 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 705 | void movl(Register dst, Register src); |
| 706 | void movl(Register dst, const Operand& src); |
| 707 | void movl(const Operand& dst, Register src); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 708 | void movl(const Operand& dst, Immediate imm); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 709 | // Load a 32-bit immediate value, zero-extended to 64 bits. |
| 710 | void movl(Register dst, Immediate imm32); |
| 711 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 712 | // Move 64 bit register value to 64-bit memory location. |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 713 | void movq(const Operand& dst, Register src); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 714 | // Move 64 bit memory location to 64-bit register value. |
| 715 | void movq(Register dst, const Operand& src); |
| 716 | void movq(Register dst, Register src); |
| 717 | // Sign extends immediate 32-bit value to 64 bits. |
| 718 | void movq(Register dst, Immediate x); |
| 719 | // Move the offset of the label location relative to the current |
| 720 | // position (after the move) to the destination. |
| 721 | void movl(const Operand& dst, Label* src); |
| 722 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 723 | // Move sign extended immediate to memory location. |
| 724 | void movq(const Operand& dst, Immediate value); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 725 | // Loads a pointer into a register with a relocation mode. |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 726 | void movq(Register dst, void* ptr, RelocInfo::Mode rmode); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 727 | // Loads a 64-bit immediate into a register. |
| 728 | void movq(Register dst, int64_t value); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 729 | void movq(Register dst, Handle<Object> handle, RelocInfo::Mode rmode); |
| 730 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 731 | void movsxbq(Register dst, const Operand& src); |
| 732 | void movsxwq(Register dst, const Operand& src); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 733 | void movsxlq(Register dst, Register src); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 734 | void movsxlq(Register dst, const Operand& src); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 735 | void movzxbq(Register dst, const Operand& src); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 736 | void movzxbl(Register dst, const Operand& src); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 737 | void movzxwq(Register dst, const Operand& src); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 738 | void movzxwl(Register dst, const Operand& src); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 739 | void movzxwl(Register dst, Register src); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 740 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 741 | // Repeated moves. |
| 742 | |
| 743 | void repmovsb(); |
| 744 | void repmovsw(); |
| 745 | void repmovsl(); |
| 746 | void repmovsq(); |
| 747 | |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 748 | // Instruction to load from an immediate 64-bit pointer into RAX. |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 749 | void load_rax(void* ptr, RelocInfo::Mode rmode); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 750 | void load_rax(ExternalReference ext); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 751 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 752 | // Conditional moves. |
| 753 | void cmovq(Condition cc, Register dst, Register src); |
| 754 | void cmovq(Condition cc, Register dst, const Operand& src); |
| 755 | void cmovl(Condition cc, Register dst, Register src); |
| 756 | void cmovl(Condition cc, Register dst, const Operand& src); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 757 | |
| 758 | // Exchange two registers |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 759 | void xchgq(Register dst, Register src); |
| 760 | void xchgl(Register dst, Register src); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 761 | |
| 762 | // Arithmetics |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 763 | void addl(Register dst, Register src) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 764 | arithmetic_op_32(0x03, dst, src); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 765 | } |
| 766 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 767 | void addl(Register dst, Immediate src) { |
| 768 | immediate_arithmetic_op_32(0x0, dst, src); |
| 769 | } |
| 770 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 771 | void addl(Register dst, const Operand& src) { |
| 772 | arithmetic_op_32(0x03, dst, src); |
| 773 | } |
| 774 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 775 | void addl(const Operand& dst, Immediate src) { |
| 776 | immediate_arithmetic_op_32(0x0, dst, src); |
| 777 | } |
| 778 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 779 | void addl(const Operand& dst, Register src) { |
| 780 | arithmetic_op_32(0x01, src, dst); |
| 781 | } |
| 782 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 783 | void addq(Register dst, Register src) { |
| 784 | arithmetic_op(0x03, dst, src); |
| 785 | } |
| 786 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 787 | void addq(Register dst, const Operand& src) { |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 788 | arithmetic_op(0x03, dst, src); |
| 789 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 790 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 791 | void addq(const Operand& dst, Register src) { |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 792 | arithmetic_op(0x01, src, dst); |
| 793 | } |
| 794 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 795 | void addq(Register dst, Immediate src) { |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 796 | immediate_arithmetic_op(0x0, dst, src); |
| 797 | } |
| 798 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 799 | void addq(const Operand& dst, Immediate src) { |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 800 | immediate_arithmetic_op(0x0, dst, src); |
| 801 | } |
| 802 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 803 | void sbbl(Register dst, Register src) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 804 | arithmetic_op_32(0x1b, dst, src); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 805 | } |
| 806 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 807 | void sbbq(Register dst, Register src) { |
| 808 | arithmetic_op(0x1b, dst, src); |
| 809 | } |
| 810 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 811 | void cmpb(Register dst, Immediate src) { |
| 812 | immediate_arithmetic_op_8(0x7, dst, src); |
| 813 | } |
| 814 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 815 | void cmpb_al(Immediate src); |
| 816 | |
| 817 | void cmpb(Register dst, Register src) { |
| 818 | arithmetic_op(0x3A, dst, src); |
| 819 | } |
| 820 | |
| 821 | void cmpb(Register dst, const Operand& src) { |
| 822 | arithmetic_op(0x3A, dst, src); |
| 823 | } |
| 824 | |
| 825 | void cmpb(const Operand& dst, Register src) { |
| 826 | arithmetic_op(0x38, src, dst); |
| 827 | } |
| 828 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 829 | void cmpb(const Operand& dst, Immediate src) { |
| 830 | immediate_arithmetic_op_8(0x7, dst, src); |
| 831 | } |
| 832 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 833 | void cmpw(const Operand& dst, Immediate src) { |
| 834 | immediate_arithmetic_op_16(0x7, dst, src); |
| 835 | } |
| 836 | |
| 837 | void cmpw(Register dst, Immediate src) { |
| 838 | immediate_arithmetic_op_16(0x7, dst, src); |
| 839 | } |
| 840 | |
| 841 | void cmpw(Register dst, const Operand& src) { |
| 842 | arithmetic_op_16(0x3B, dst, src); |
| 843 | } |
| 844 | |
| 845 | void cmpw(Register dst, Register src) { |
| 846 | arithmetic_op_16(0x3B, dst, src); |
| 847 | } |
| 848 | |
| 849 | void cmpw(const Operand& dst, Register src) { |
| 850 | arithmetic_op_16(0x39, src, dst); |
| 851 | } |
| 852 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 853 | void cmpl(Register dst, Register src) { |
| 854 | arithmetic_op_32(0x3B, dst, src); |
| 855 | } |
| 856 | |
| 857 | void cmpl(Register dst, const Operand& src) { |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 858 | arithmetic_op_32(0x3B, dst, src); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | void cmpl(const Operand& dst, Register src) { |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 862 | arithmetic_op_32(0x39, src, dst); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | void cmpl(Register dst, Immediate src) { |
| 866 | immediate_arithmetic_op_32(0x7, dst, src); |
| 867 | } |
| 868 | |
| 869 | void cmpl(const Operand& dst, Immediate src) { |
| 870 | immediate_arithmetic_op_32(0x7, dst, src); |
| 871 | } |
| 872 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 873 | void cmpq(Register dst, Register src) { |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 874 | arithmetic_op(0x3B, dst, src); |
| 875 | } |
| 876 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 877 | void cmpq(Register dst, const Operand& src) { |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 878 | arithmetic_op(0x3B, dst, src); |
| 879 | } |
| 880 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 881 | void cmpq(const Operand& dst, Register src) { |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 882 | arithmetic_op(0x39, src, dst); |
| 883 | } |
| 884 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 885 | void cmpq(Register dst, Immediate src) { |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 886 | immediate_arithmetic_op(0x7, dst, src); |
| 887 | } |
| 888 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 889 | void cmpq(const Operand& dst, Immediate src) { |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 890 | immediate_arithmetic_op(0x7, dst, src); |
| 891 | } |
| 892 | |
| 893 | void and_(Register dst, Register src) { |
| 894 | arithmetic_op(0x23, dst, src); |
| 895 | } |
| 896 | |
| 897 | void and_(Register dst, const Operand& src) { |
| 898 | arithmetic_op(0x23, dst, src); |
| 899 | } |
| 900 | |
| 901 | void and_(const Operand& dst, Register src) { |
| 902 | arithmetic_op(0x21, src, dst); |
| 903 | } |
| 904 | |
| 905 | void and_(Register dst, Immediate src) { |
| 906 | immediate_arithmetic_op(0x4, dst, src); |
| 907 | } |
| 908 | |
| 909 | void and_(const Operand& dst, Immediate src) { |
| 910 | immediate_arithmetic_op(0x4, dst, src); |
| 911 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 912 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 913 | void andl(Register dst, Immediate src) { |
| 914 | immediate_arithmetic_op_32(0x4, dst, src); |
| 915 | } |
| 916 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 917 | void andl(Register dst, Register src) { |
| 918 | arithmetic_op_32(0x23, dst, src); |
| 919 | } |
| 920 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 921 | void andl(Register dst, const Operand& src) { |
| 922 | arithmetic_op_32(0x23, dst, src); |
| 923 | } |
| 924 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 925 | void andb(Register dst, Immediate src) { |
| 926 | immediate_arithmetic_op_8(0x4, dst, src); |
| 927 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 928 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 929 | void decq(Register dst); |
| 930 | void decq(const Operand& dst); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 931 | void decl(Register dst); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 932 | void decl(const Operand& dst); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 933 | void decb(Register dst); |
| 934 | void decb(const Operand& dst); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 935 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 936 | // Sign-extends rax into rdx:rax. |
| 937 | void cqo(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 938 | // Sign-extends eax into edx:eax. |
| 939 | void cdq(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 940 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 941 | // Divide rdx:rax by src. Quotient in rax, remainder in rdx. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 942 | void idivq(Register src); |
| 943 | // Divide edx:eax by lower 32 bits of src. Quotient in eax, rem. in edx. |
| 944 | void idivl(Register src); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 945 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 946 | // Signed multiply instructions. |
| 947 | void imul(Register src); // rdx:rax = rax * src. |
| 948 | void imul(Register dst, Register src); // dst = dst * src. |
| 949 | void imul(Register dst, const Operand& src); // dst = dst * src. |
| 950 | void imul(Register dst, Register src, Immediate imm); // dst = src * imm. |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 951 | // Signed 32-bit multiply instructions. |
| 952 | void imull(Register dst, Register src); // dst = dst * src. |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 953 | void imull(Register dst, const Operand& src); // dst = dst * src. |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 954 | void imull(Register dst, Register src, Immediate imm); // dst = src * imm. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 955 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 956 | void incq(Register dst); |
| 957 | void incq(const Operand& dst); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 958 | void incl(Register dst); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 959 | void incl(const Operand& dst); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 960 | |
| 961 | void lea(Register dst, const Operand& src); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 962 | void leal(Register dst, const Operand& src); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 963 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 964 | // Multiply rax by src, put the result in rdx:rax. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 965 | void mul(Register src); |
| 966 | |
| 967 | void neg(Register dst); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 968 | void neg(const Operand& dst); |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 969 | void negl(Register dst); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 970 | |
| 971 | void not_(Register dst); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 972 | void not_(const Operand& dst); |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 973 | void notl(Register dst); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 974 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 975 | void or_(Register dst, Register src) { |
| 976 | arithmetic_op(0x0B, dst, src); |
| 977 | } |
| 978 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 979 | void orl(Register dst, Register src) { |
| 980 | arithmetic_op_32(0x0B, dst, src); |
| 981 | } |
| 982 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 983 | void or_(Register dst, const Operand& src) { |
| 984 | arithmetic_op(0x0B, dst, src); |
| 985 | } |
| 986 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 987 | void orl(Register dst, const Operand& src) { |
| 988 | arithmetic_op_32(0x0B, dst, src); |
| 989 | } |
| 990 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 991 | void or_(const Operand& dst, Register src) { |
| 992 | arithmetic_op(0x09, src, dst); |
| 993 | } |
| 994 | |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 995 | void orl(const Operand& dst, Register src) { |
| 996 | arithmetic_op_32(0x09, src, dst); |
| 997 | } |
| 998 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 999 | void or_(Register dst, Immediate src) { |
| 1000 | immediate_arithmetic_op(0x1, dst, src); |
| 1001 | } |
| 1002 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1003 | void orl(Register dst, Immediate src) { |
| 1004 | immediate_arithmetic_op_32(0x1, dst, src); |
| 1005 | } |
| 1006 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1007 | void or_(const Operand& dst, Immediate src) { |
| 1008 | immediate_arithmetic_op(0x1, dst, src); |
| 1009 | } |
| 1010 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1011 | void orl(const Operand& dst, Immediate src) { |
| 1012 | immediate_arithmetic_op_32(0x1, dst, src); |
| 1013 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1014 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1015 | |
| 1016 | void rcl(Register dst, Immediate imm8) { |
| 1017 | shift(dst, imm8, 0x2); |
| 1018 | } |
| 1019 | |
| 1020 | void rol(Register dst, Immediate imm8) { |
| 1021 | shift(dst, imm8, 0x0); |
| 1022 | } |
| 1023 | |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 1024 | void roll(Register dst, Immediate imm8) { |
| 1025 | shift_32(dst, imm8, 0x0); |
| 1026 | } |
| 1027 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1028 | void rcr(Register dst, Immediate imm8) { |
| 1029 | shift(dst, imm8, 0x3); |
| 1030 | } |
| 1031 | |
| 1032 | void ror(Register dst, Immediate imm8) { |
| 1033 | shift(dst, imm8, 0x1); |
| 1034 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1035 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1036 | void rorl(Register dst, Immediate imm8) { |
| 1037 | shift_32(dst, imm8, 0x1); |
| 1038 | } |
| 1039 | |
| 1040 | void rorl_cl(Register dst) { |
| 1041 | shift_32(dst, 0x1); |
| 1042 | } |
| 1043 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1044 | // Shifts dst:src left by cl bits, affecting only dst. |
| 1045 | void shld(Register dst, Register src); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1046 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1047 | // Shifts src:dst right by cl bits, affecting only dst. |
| 1048 | void shrd(Register dst, Register src); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1049 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1050 | // Shifts dst right, duplicating sign bit, by shift_amount bits. |
| 1051 | // Shifting by 1 is handled efficiently. |
| 1052 | void sar(Register dst, Immediate shift_amount) { |
| 1053 | shift(dst, shift_amount, 0x7); |
| 1054 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1055 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1056 | // Shifts dst right, duplicating sign bit, by shift_amount bits. |
| 1057 | // Shifting by 1 is handled efficiently. |
| 1058 | void sarl(Register dst, Immediate shift_amount) { |
| 1059 | shift_32(dst, shift_amount, 0x7); |
| 1060 | } |
| 1061 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1062 | // Shifts dst right, duplicating sign bit, by cl % 64 bits. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1063 | void sar_cl(Register dst) { |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1064 | shift(dst, 0x7); |
| 1065 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1066 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1067 | // Shifts dst right, duplicating sign bit, by cl % 64 bits. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1068 | void sarl_cl(Register dst) { |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1069 | shift_32(dst, 0x7); |
| 1070 | } |
| 1071 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1072 | void shl(Register dst, Immediate shift_amount) { |
| 1073 | shift(dst, shift_amount, 0x4); |
| 1074 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1075 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1076 | void shl_cl(Register dst) { |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1077 | shift(dst, 0x4); |
| 1078 | } |
| 1079 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1080 | void shll_cl(Register dst) { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1081 | shift_32(dst, 0x4); |
| 1082 | } |
| 1083 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1084 | void shll(Register dst, Immediate shift_amount) { |
| 1085 | shift_32(dst, shift_amount, 0x4); |
| 1086 | } |
| 1087 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1088 | void shr(Register dst, Immediate shift_amount) { |
| 1089 | shift(dst, shift_amount, 0x5); |
| 1090 | } |
| 1091 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1092 | void shr_cl(Register dst) { |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1093 | shift(dst, 0x5); |
| 1094 | } |
| 1095 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1096 | void shrl_cl(Register dst) { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1097 | shift_32(dst, 0x5); |
| 1098 | } |
| 1099 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1100 | void shrl(Register dst, Immediate shift_amount) { |
| 1101 | shift_32(dst, shift_amount, 0x5); |
| 1102 | } |
| 1103 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1104 | void store_rax(void* dst, RelocInfo::Mode mode); |
| 1105 | void store_rax(ExternalReference ref); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1106 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1107 | void subq(Register dst, Register src) { |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1108 | arithmetic_op(0x2B, dst, src); |
| 1109 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1110 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1111 | void subq(Register dst, const Operand& src) { |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1112 | arithmetic_op(0x2B, dst, src); |
| 1113 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1114 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1115 | void subq(const Operand& dst, Register src) { |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1116 | arithmetic_op(0x29, src, dst); |
| 1117 | } |
| 1118 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1119 | void subq(Register dst, Immediate src) { |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1120 | immediate_arithmetic_op(0x5, dst, src); |
| 1121 | } |
| 1122 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1123 | void subq(const Operand& dst, Immediate src) { |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1124 | immediate_arithmetic_op(0x5, dst, src); |
| 1125 | } |
| 1126 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1127 | void subl(Register dst, Register src) { |
| 1128 | arithmetic_op_32(0x2B, dst, src); |
| 1129 | } |
| 1130 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1131 | void subl(Register dst, const Operand& src) { |
| 1132 | arithmetic_op_32(0x2B, dst, src); |
| 1133 | } |
| 1134 | |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 1135 | void subl(const Operand& dst, Register src) { |
| 1136 | arithmetic_op_32(0x29, src, dst); |
| 1137 | } |
| 1138 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1139 | void subl(const Operand& dst, Immediate src) { |
| 1140 | immediate_arithmetic_op_32(0x5, dst, src); |
| 1141 | } |
| 1142 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1143 | void subl(Register dst, Immediate src) { |
| 1144 | immediate_arithmetic_op_32(0x5, dst, src); |
| 1145 | } |
| 1146 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1147 | void subb(Register dst, Immediate src) { |
| 1148 | immediate_arithmetic_op_8(0x5, dst, src); |
| 1149 | } |
| 1150 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1151 | void testb(Register dst, Register src); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1152 | void testb(Register reg, Immediate mask); |
| 1153 | void testb(const Operand& op, Immediate mask); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1154 | void testb(const Operand& op, Register reg); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 1155 | void testl(Register dst, Register src); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1156 | void testl(Register reg, Immediate mask); |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 1157 | void testl(const Operand& op, Register reg); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1158 | void testl(const Operand& op, Immediate mask); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1159 | void testq(const Operand& op, Register reg); |
| 1160 | void testq(Register dst, Register src); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1161 | void testq(Register dst, Immediate mask); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1162 | |
| 1163 | void xor_(Register dst, Register src) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1164 | if (dst.code() == src.code()) { |
| 1165 | arithmetic_op_32(0x33, dst, src); |
| 1166 | } else { |
| 1167 | arithmetic_op(0x33, dst, src); |
| 1168 | } |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1171 | void xorl(Register dst, Register src) { |
| 1172 | arithmetic_op_32(0x33, dst, src); |
| 1173 | } |
| 1174 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1175 | void xorl(Register dst, const Operand& src) { |
| 1176 | arithmetic_op_32(0x33, dst, src); |
| 1177 | } |
| 1178 | |
| 1179 | void xorl(Register dst, Immediate src) { |
| 1180 | immediate_arithmetic_op_32(0x6, dst, src); |
| 1181 | } |
| 1182 | |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 1183 | void xorl(const Operand& dst, Register src) { |
| 1184 | arithmetic_op_32(0x31, src, dst); |
| 1185 | } |
| 1186 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1187 | void xorl(const Operand& dst, Immediate src) { |
| 1188 | immediate_arithmetic_op_32(0x6, dst, src); |
| 1189 | } |
| 1190 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1191 | void xor_(Register dst, const Operand& src) { |
| 1192 | arithmetic_op(0x33, dst, src); |
| 1193 | } |
| 1194 | |
| 1195 | void xor_(const Operand& dst, Register src) { |
| 1196 | arithmetic_op(0x31, src, dst); |
| 1197 | } |
| 1198 | |
| 1199 | void xor_(Register dst, Immediate src) { |
| 1200 | immediate_arithmetic_op(0x6, dst, src); |
| 1201 | } |
| 1202 | |
| 1203 | void xor_(const Operand& dst, Immediate src) { |
| 1204 | immediate_arithmetic_op(0x6, dst, src); |
| 1205 | } |
| 1206 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1207 | // Bit operations. |
| 1208 | void bt(const Operand& dst, Register src); |
| 1209 | void bts(const Operand& dst, Register src); |
| 1210 | |
| 1211 | // Miscellaneous |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1212 | void clc(); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1213 | void cld(); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1214 | void cpuid(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1215 | void hlt(); |
| 1216 | void int3(); |
| 1217 | void nop(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1218 | void ret(int imm16); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1219 | void setcc(Condition cc, Register reg); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1220 | |
| 1221 | // Label operations & relative jumps (PPUM Appendix D) |
| 1222 | // |
| 1223 | // Takes a branch opcode (cc) and a label (L) and generates |
| 1224 | // either a backward branch or a forward branch and links it |
| 1225 | // to the label fixup chain. Usage: |
| 1226 | // |
| 1227 | // Label L; // unbound label |
| 1228 | // j(cc, &L); // forward branch to unbound label |
| 1229 | // bind(&L); // bind label to the current pc |
| 1230 | // j(cc, &L); // backward branch to bound label |
| 1231 | // bind(&L); // illegal: a label may be bound only once |
| 1232 | // |
| 1233 | // Note: The same Label can be used for forward and backward branches |
| 1234 | // but it may be bound only once. |
| 1235 | |
| 1236 | void bind(Label* L); // binds an unbound label L to the current code position |
| 1237 | |
| 1238 | // Calls |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1239 | // Call near relative 32-bit displacement, relative to next instruction. |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1240 | void call(Label* L); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1241 | void call(Address entry, RelocInfo::Mode rmode); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1242 | void call(Handle<Code> target, |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1243 | RelocInfo::Mode rmode = RelocInfo::CODE_TARGET, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1244 | TypeFeedbackId ast_id = TypeFeedbackId::None()); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1245 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1246 | // Calls directly to the given address using a relative offset. |
| 1247 | // Should only ever be used in Code objects for calls within the |
| 1248 | // same Code object. Should not be used when generating new code (use labels), |
| 1249 | // but only when patching existing code. |
| 1250 | void call(Address target); |
| 1251 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1252 | // Call near absolute indirect, address in register |
| 1253 | void call(Register adr); |
| 1254 | |
| 1255 | // Call near indirect |
| 1256 | void call(const Operand& operand); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1257 | |
| 1258 | // Jumps |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1259 | // Jump short or near relative. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1260 | // Use a 32-bit signed displacement. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1261 | // Unconditional jump to L |
| 1262 | void jmp(Label* L, Label::Distance distance = Label::kFar); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1263 | void jmp(Address entry, RelocInfo::Mode rmode); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1264 | void jmp(Handle<Code> target, RelocInfo::Mode rmode); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1265 | |
| 1266 | // Jump near absolute indirect (r64) |
| 1267 | void jmp(Register adr); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1268 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1269 | // Jump near absolute indirect (m64) |
| 1270 | void jmp(const Operand& src); |
| 1271 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1272 | // Conditional jumps |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1273 | void j(Condition cc, |
| 1274 | Label* L, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1275 | Label::Distance distance = Label::kFar); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1276 | void j(Condition cc, Address entry, RelocInfo::Mode rmode); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1277 | void j(Condition cc, Handle<Code> target, RelocInfo::Mode rmode); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1278 | |
| 1279 | // Floating-point operations |
| 1280 | void fld(int i); |
| 1281 | |
| 1282 | void fld1(); |
| 1283 | void fldz(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1284 | void fldpi(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1285 | void fldln2(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1286 | |
| 1287 | void fld_s(const Operand& adr); |
| 1288 | void fld_d(const Operand& adr); |
| 1289 | |
| 1290 | void fstp_s(const Operand& adr); |
| 1291 | void fstp_d(const Operand& adr); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1292 | void fstp(int index); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1293 | |
| 1294 | void fild_s(const Operand& adr); |
| 1295 | void fild_d(const Operand& adr); |
| 1296 | |
| 1297 | void fist_s(const Operand& adr); |
| 1298 | |
| 1299 | void fistp_s(const Operand& adr); |
| 1300 | void fistp_d(const Operand& adr); |
| 1301 | |
| 1302 | void fisttp_s(const Operand& adr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1303 | void fisttp_d(const Operand& adr); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1304 | |
| 1305 | void fabs(); |
| 1306 | void fchs(); |
| 1307 | |
| 1308 | void fadd(int i); |
| 1309 | void fsub(int i); |
| 1310 | void fmul(int i); |
| 1311 | void fdiv(int i); |
| 1312 | |
| 1313 | void fisub_s(const Operand& adr); |
| 1314 | |
| 1315 | void faddp(int i = 1); |
| 1316 | void fsubp(int i = 1); |
| 1317 | void fsubrp(int i = 1); |
| 1318 | void fmulp(int i = 1); |
| 1319 | void fdivp(int i = 1); |
| 1320 | void fprem(); |
| 1321 | void fprem1(); |
| 1322 | |
| 1323 | void fxch(int i = 1); |
| 1324 | void fincstp(); |
| 1325 | void ffree(int i = 0); |
| 1326 | |
| 1327 | void ftst(); |
| 1328 | void fucomp(int i); |
| 1329 | void fucompp(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1330 | void fucomi(int i); |
| 1331 | void fucomip(); |
| 1332 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1333 | void fcompp(); |
| 1334 | void fnstsw_ax(); |
| 1335 | void fwait(); |
| 1336 | void fnclex(); |
| 1337 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1338 | void fsin(); |
| 1339 | void fcos(); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1340 | void fptan(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1341 | void fyl2x(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1342 | void f2xm1(); |
| 1343 | void fscale(); |
| 1344 | void fninit(); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1345 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1346 | void frndint(); |
| 1347 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1348 | void sahf(); |
| 1349 | |
jkummerow@chromium.org | ef33a54 | 2013-10-28 18:03:37 +0000 | [diff] [blame] | 1350 | // SSE instructions |
| 1351 | void movaps(XMMRegister dst, XMMRegister src); |
| 1352 | void movss(XMMRegister dst, const Operand& src); |
| 1353 | void movss(const Operand& dst, XMMRegister src); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 1354 | void shufps(XMMRegister dst, XMMRegister src, byte imm8); |
jkummerow@chromium.org | ef33a54 | 2013-10-28 18:03:37 +0000 | [diff] [blame] | 1355 | |
| 1356 | void cvttss2si(Register dst, const Operand& src); |
| 1357 | void cvttss2si(Register dst, XMMRegister src); |
| 1358 | void cvtlsi2ss(XMMRegister dst, Register src); |
| 1359 | |
jkummerow@chromium.org | ef33a54 | 2013-10-28 18:03:37 +0000 | [diff] [blame] | 1360 | void andps(XMMRegister dst, XMMRegister src); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 1361 | void andps(XMMRegister dst, const Operand& src); |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 1362 | void orps(XMMRegister dst, XMMRegister src); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 1363 | void orps(XMMRegister dst, const Operand& src); |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 1364 | void xorps(XMMRegister dst, XMMRegister src); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 1365 | void xorps(XMMRegister dst, const Operand& src); |
| 1366 | |
| 1367 | void addps(XMMRegister dst, XMMRegister src); |
| 1368 | void addps(XMMRegister dst, const Operand& src); |
| 1369 | void subps(XMMRegister dst, XMMRegister src); |
| 1370 | void subps(XMMRegister dst, const Operand& src); |
| 1371 | void mulps(XMMRegister dst, XMMRegister src); |
| 1372 | void mulps(XMMRegister dst, const Operand& src); |
| 1373 | void divps(XMMRegister dst, XMMRegister src); |
| 1374 | void divps(XMMRegister dst, const Operand& src); |
jkummerow@chromium.org | ef33a54 | 2013-10-28 18:03:37 +0000 | [diff] [blame] | 1375 | |
| 1376 | void movmskps(Register dst, XMMRegister src); |
| 1377 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1378 | // SSE2 instructions |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1379 | void movd(XMMRegister dst, Register src); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1380 | void movd(Register dst, XMMRegister src); |
| 1381 | void movq(XMMRegister dst, Register src); |
| 1382 | void movq(Register dst, XMMRegister src); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1383 | void movq(XMMRegister dst, XMMRegister src); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1384 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1385 | // Don't use this unless it's important to keep the |
| 1386 | // top half of the destination register unchanged. |
| 1387 | // Used movaps when moving double values and movq for integer |
| 1388 | // values in xmm registers. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1389 | void movsd(XMMRegister dst, XMMRegister src); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1390 | |
| 1391 | void movsd(const Operand& dst, XMMRegister src); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1392 | void movsd(XMMRegister dst, const Operand& src); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1393 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1394 | void movdqa(const Operand& dst, XMMRegister src); |
| 1395 | void movdqa(XMMRegister dst, const Operand& src); |
| 1396 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1397 | void movdqu(const Operand& dst, XMMRegister src); |
| 1398 | void movdqu(XMMRegister dst, const Operand& src); |
| 1399 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1400 | void movapd(XMMRegister dst, XMMRegister src); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1401 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1402 | void cvttsd2si(Register dst, const Operand& src); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1403 | void cvttsd2si(Register dst, XMMRegister src); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1404 | void cvttsd2siq(Register dst, XMMRegister src); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1405 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1406 | void cvtlsi2sd(XMMRegister dst, const Operand& src); |
| 1407 | void cvtlsi2sd(XMMRegister dst, Register src); |
| 1408 | void cvtqsi2sd(XMMRegister dst, const Operand& src); |
| 1409 | void cvtqsi2sd(XMMRegister dst, Register src); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1410 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1411 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1412 | void cvtss2sd(XMMRegister dst, XMMRegister src); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1413 | void cvtss2sd(XMMRegister dst, const Operand& src); |
| 1414 | void cvtsd2ss(XMMRegister dst, XMMRegister src); |
| 1415 | |
| 1416 | void cvtsd2si(Register dst, XMMRegister src); |
| 1417 | void cvtsd2siq(Register dst, XMMRegister src); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1418 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1419 | void addsd(XMMRegister dst, XMMRegister src); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 1420 | void addsd(XMMRegister dst, const Operand& src); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1421 | void subsd(XMMRegister dst, XMMRegister src); |
| 1422 | void mulsd(XMMRegister dst, XMMRegister src); |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 1423 | void mulsd(XMMRegister dst, const Operand& src); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1424 | void divsd(XMMRegister dst, XMMRegister src); |
| 1425 | |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1426 | void andpd(XMMRegister dst, XMMRegister src); |
| 1427 | void orpd(XMMRegister dst, XMMRegister src); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1428 | void xorpd(XMMRegister dst, XMMRegister src); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 1429 | void sqrtsd(XMMRegister dst, XMMRegister src); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1430 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1431 | void ucomisd(XMMRegister dst, XMMRegister src); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1432 | void ucomisd(XMMRegister dst, const Operand& src); |
jkummerow@chromium.org | ef33a54 | 2013-10-28 18:03:37 +0000 | [diff] [blame] | 1433 | void cmpltsd(XMMRegister dst, XMMRegister src); |
| 1434 | |
| 1435 | void movmskpd(Register dst, XMMRegister src); |
| 1436 | |
| 1437 | // SSE 4.1 instruction |
| 1438 | void extractps(Register dst, XMMRegister src, byte imm8); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1439 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1440 | enum RoundingMode { |
| 1441 | kRoundToNearest = 0x0, |
| 1442 | kRoundDown = 0x1, |
| 1443 | kRoundUp = 0x2, |
| 1444 | kRoundToZero = 0x3 |
| 1445 | }; |
| 1446 | |
| 1447 | void roundsd(XMMRegister dst, XMMRegister src, RoundingMode mode); |
| 1448 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1449 | // Debugging |
| 1450 | void Print(); |
| 1451 | |
| 1452 | // Check the code size generated from label to here. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1453 | int SizeOfCodeGeneratedSince(Label* label) { |
| 1454 | return pc_offset() - label->pos(); |
| 1455 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1456 | |
| 1457 | // Mark address of the ExitJSFrame code. |
| 1458 | void RecordJSReturn(); |
| 1459 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1460 | // Mark address of a debug break slot. |
| 1461 | void RecordDebugBreakSlot(); |
| 1462 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1463 | // Record a comment relocation entry that can be used by a disassembler. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1464 | // Use --code-comments to enable. |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1465 | void RecordComment(const char* msg, bool force = false); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1466 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1467 | // Writes a single word of data in the code stream. |
| 1468 | // Used for inline tables, e.g., jump-tables. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1469 | void db(uint8_t data); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1470 | void dd(uint32_t data); |
| 1471 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1472 | PositionsRecorder* positions_recorder() { return &positions_recorder_; } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1473 | |
| 1474 | // Check if there is less than kGap bytes available in the buffer. |
| 1475 | // If this is the case, we need to grow the buffer before emitting |
| 1476 | // an instruction or relocation information. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1477 | inline bool buffer_overflow() const { |
| 1478 | return pc_ >= reloc_info_writer.pos() - kGap; |
| 1479 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1480 | |
| 1481 | // Get the number of bytes available in the buffer. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1482 | inline int available_space() const { |
| 1483 | return static_cast<int>(reloc_info_writer.pos() - pc_); |
| 1484 | } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1485 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1486 | static bool IsNop(Address addr); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1487 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1488 | // Avoid overflows for displacements etc. |
| 1489 | static const int kMaximalBufferSize = 512*MB; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1490 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1491 | byte byte_at(int pos) { return buffer_[pos]; } |
| 1492 | void set_byte_at(int pos, byte value) { buffer_[pos] = value; } |
| 1493 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1494 | private: |
| 1495 | byte* addr_at(int pos) { return buffer_ + pos; } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1496 | uint32_t long_at(int pos) { |
| 1497 | return *reinterpret_cast<uint32_t*>(addr_at(pos)); |
| 1498 | } |
| 1499 | void long_at_put(int pos, uint32_t x) { |
| 1500 | *reinterpret_cast<uint32_t*>(addr_at(pos)) = x; |
| 1501 | } |
| 1502 | |
| 1503 | // code emission |
| 1504 | void GrowBuffer(); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1505 | |
| 1506 | void emit(byte x) { *pc_++ = x; } |
| 1507 | inline void emitl(uint32_t x); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1508 | inline void emitp(void* x, RelocInfo::Mode rmode); |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 1509 | inline void emitq(uint64_t x); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1510 | inline void emitw(uint16_t x); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1511 | inline void emit_code_target(Handle<Code> target, |
| 1512 | RelocInfo::Mode rmode, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1513 | TypeFeedbackId ast_id = TypeFeedbackId::None()); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 1514 | inline void emit_runtime_entry(Address entry, RelocInfo::Mode rmode); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1515 | void emit(Immediate x) { emitl(x.value_); } |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1516 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1517 | // Emits a REX prefix that encodes a 64-bit operand size and |
| 1518 | // the top bit of both register codes. |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1519 | // High bit of reg goes to REX.R, high bit of rm_reg goes to REX.B. |
| 1520 | // REX.W is set. |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1521 | inline void emit_rex_64(XMMRegister reg, Register rm_reg); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1522 | inline void emit_rex_64(Register reg, XMMRegister rm_reg); |
| 1523 | inline void emit_rex_64(Register reg, Register rm_reg); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1524 | |
| 1525 | // Emits a REX prefix that encodes a 64-bit operand size and |
| 1526 | // the top bit of the destination, index, and base register codes. |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1527 | // The high bit of reg is used for REX.R, the high bit of op's base |
| 1528 | // register is used for REX.B, and the high bit of op's index register |
| 1529 | // is used for REX.X. REX.W is set. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1530 | inline void emit_rex_64(Register reg, const Operand& op); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1531 | inline void emit_rex_64(XMMRegister reg, const Operand& op); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1532 | |
| 1533 | // Emits a REX prefix that encodes a 64-bit operand size and |
| 1534 | // the top bit of the register code. |
| 1535 | // The high bit of register is used for REX.B. |
| 1536 | // REX.W is set and REX.R and REX.X are clear. |
| 1537 | inline void emit_rex_64(Register rm_reg); |
| 1538 | |
| 1539 | // Emits a REX prefix that encodes a 64-bit operand size and |
| 1540 | // the top bit of the index and base register codes. |
| 1541 | // The high bit of op's base register is used for REX.B, and the high |
| 1542 | // bit of op's index register is used for REX.X. |
| 1543 | // REX.W is set and REX.R clear. |
| 1544 | inline void emit_rex_64(const Operand& op); |
| 1545 | |
| 1546 | // Emit a REX prefix that only sets REX.W to choose a 64-bit operand size. |
| 1547 | void emit_rex_64() { emit(0x48); } |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1548 | |
| 1549 | // High bit of reg goes to REX.R, high bit of rm_reg goes to REX.B. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1550 | // REX.W is clear. |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1551 | inline void emit_rex_32(Register reg, Register rm_reg); |
| 1552 | |
| 1553 | // The high bit of reg is used for REX.R, the high bit of op's base |
| 1554 | // register is used for REX.B, and the high bit of op's index register |
| 1555 | // is used for REX.X. REX.W is cleared. |
| 1556 | inline void emit_rex_32(Register reg, const Operand& op); |
| 1557 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1558 | // High bit of rm_reg goes to REX.B. |
| 1559 | // REX.W, REX.R and REX.X are clear. |
| 1560 | inline void emit_rex_32(Register rm_reg); |
| 1561 | |
| 1562 | // High bit of base goes to REX.B and high bit of index to REX.X. |
| 1563 | // REX.W and REX.R are clear. |
| 1564 | inline void emit_rex_32(const Operand& op); |
| 1565 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1566 | // High bit of reg goes to REX.R, high bit of rm_reg goes to REX.B. |
| 1567 | // REX.W is cleared. If no REX bits are set, no byte is emitted. |
| 1568 | inline void emit_optional_rex_32(Register reg, Register rm_reg); |
| 1569 | |
| 1570 | // The high bit of reg is used for REX.R, the high bit of op's base |
| 1571 | // register is used for REX.B, and the high bit of op's index register |
| 1572 | // is used for REX.X. REX.W is cleared. If no REX bits are set, nothing |
| 1573 | // is emitted. |
| 1574 | inline void emit_optional_rex_32(Register reg, const Operand& op); |
| 1575 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1576 | // As for emit_optional_rex_32(Register, Register), except that |
| 1577 | // the registers are XMM registers. |
| 1578 | inline void emit_optional_rex_32(XMMRegister reg, XMMRegister base); |
| 1579 | |
| 1580 | // As for emit_optional_rex_32(Register, Register), except that |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1581 | // one of the registers is an XMM registers. |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1582 | inline void emit_optional_rex_32(XMMRegister reg, Register base); |
| 1583 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1584 | // As for emit_optional_rex_32(Register, Register), except that |
| 1585 | // one of the registers is an XMM registers. |
| 1586 | inline void emit_optional_rex_32(Register reg, XMMRegister base); |
| 1587 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1588 | // As for emit_optional_rex_32(Register, const Operand&), except that |
| 1589 | // the register is an XMM register. |
| 1590 | inline void emit_optional_rex_32(XMMRegister reg, const Operand& op); |
| 1591 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1592 | // Optionally do as emit_rex_32(Register) if the register number has |
| 1593 | // the high bit set. |
| 1594 | inline void emit_optional_rex_32(Register rm_reg); |
| 1595 | |
| 1596 | // Optionally do as emit_rex_32(const Operand&) if the operand register |
| 1597 | // numbers have a high bit set. |
| 1598 | inline void emit_optional_rex_32(const Operand& op); |
| 1599 | |
| 1600 | |
| 1601 | // Emit the ModR/M byte, and optionally the SIB byte and |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1602 | // 1- or 4-byte offset for a memory operand. Also encodes |
| 1603 | // the second operand of the operation, a register or operation |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1604 | // subcode, into the reg field of the ModR/M byte. |
| 1605 | void emit_operand(Register reg, const Operand& adr) { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1606 | emit_operand(reg.low_bits(), adr); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
| 1609 | // Emit the ModR/M byte, and optionally the SIB byte and |
| 1610 | // 1- or 4-byte offset for a memory operand. Also used to encode |
| 1611 | // a three-bit opcode extension into the ModR/M byte. |
| 1612 | void emit_operand(int rm, const Operand& adr); |
| 1613 | |
| 1614 | // Emit a ModR/M byte with registers coded in the reg and rm_reg fields. |
| 1615 | void emit_modrm(Register reg, Register rm_reg) { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1616 | emit(0xC0 | reg.low_bits() << 3 | rm_reg.low_bits()); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | // Emit a ModR/M byte with an operation subcode in the reg field and |
| 1620 | // a register in the rm_reg field. |
| 1621 | void emit_modrm(int code, Register rm_reg) { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1622 | ASSERT(is_uint3(code)); |
| 1623 | emit(0xC0 | code << 3 | rm_reg.low_bits()); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1624 | } |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1625 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1626 | // Emit the code-object-relative offset of the label's position |
| 1627 | inline void emit_code_relative_offset(Label* label); |
| 1628 | |
jkummerow@chromium.org | ef33a54 | 2013-10-28 18:03:37 +0000 | [diff] [blame] | 1629 | // The first argument is the reg field, the second argument is the r/m field. |
| 1630 | void emit_sse_operand(XMMRegister dst, XMMRegister src); |
| 1631 | void emit_sse_operand(XMMRegister reg, const Operand& adr); |
| 1632 | void emit_sse_operand(XMMRegister dst, Register src); |
| 1633 | void emit_sse_operand(Register dst, XMMRegister src); |
| 1634 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1635 | // Emit machine code for one of the operations ADD, ADC, SUB, SBC, |
| 1636 | // AND, OR, XOR, or CMP. The encodings of these operations are all |
| 1637 | // similar, differing just in the opcode or in the reg field of the |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1638 | // ModR/M byte. |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1639 | void arithmetic_op_16(byte opcode, Register reg, Register rm_reg); |
| 1640 | void arithmetic_op_16(byte opcode, Register reg, const Operand& rm_reg); |
| 1641 | void arithmetic_op_32(byte opcode, Register reg, Register rm_reg); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1642 | void arithmetic_op_32(byte opcode, Register reg, const Operand& rm_reg); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1643 | void arithmetic_op(byte opcode, Register reg, Register rm_reg); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1644 | void arithmetic_op(byte opcode, Register reg, const Operand& rm_reg); |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 1645 | void immediate_arithmetic_op(byte subcode, Register dst, Immediate src); |
| 1646 | void immediate_arithmetic_op(byte subcode, const Operand& dst, Immediate src); |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1647 | // Operate on a byte in memory or register. |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1648 | void immediate_arithmetic_op_8(byte subcode, |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 1649 | Register dst, |
| 1650 | Immediate src); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1651 | void immediate_arithmetic_op_8(byte subcode, |
| 1652 | const Operand& dst, |
| 1653 | Immediate src); |
| 1654 | // Operate on a word in memory or register. |
| 1655 | void immediate_arithmetic_op_16(byte subcode, |
| 1656 | Register dst, |
| 1657 | Immediate src); |
| 1658 | void immediate_arithmetic_op_16(byte subcode, |
| 1659 | const Operand& dst, |
| 1660 | Immediate src); |
| 1661 | // Operate on a 32-bit word in memory or register. |
| 1662 | void immediate_arithmetic_op_32(byte subcode, |
| 1663 | Register dst, |
| 1664 | Immediate src); |
| 1665 | void immediate_arithmetic_op_32(byte subcode, |
| 1666 | const Operand& dst, |
| 1667 | Immediate src); |
| 1668 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1669 | // Emit machine code for a shift operation. |
| 1670 | void shift(Register dst, Immediate shift_amount, int subcode); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1671 | void shift_32(Register dst, Immediate shift_amount, int subcode); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 1672 | // Shift dst by cl % 64 bits. |
| 1673 | void shift(Register dst, int subcode); |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1674 | void shift_32(Register dst, int subcode); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1675 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 1676 | void emit_farith(int b1, int b2, int i); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1677 | |
| 1678 | // labels |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1679 | // void print(Label* L); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1680 | void bind_to(Label* L, int pos); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1681 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1682 | // record reloc info for current pc_ |
| 1683 | void RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data = 0); |
| 1684 | |
| 1685 | friend class CodePatcher; |
| 1686 | friend class EnsureSpace; |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1687 | friend class RegExpMacroAssemblerX64; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1688 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1689 | // code generation |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1690 | RelocInfoWriter reloc_info_writer; |
| 1691 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 1692 | List< Handle<Code> > code_targets_; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1693 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1694 | PositionsRecorder positions_recorder_; |
| 1695 | friend class PositionsRecorder; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1696 | }; |
| 1697 | |
| 1698 | |
| 1699 | // Helper class that ensures that there is enough space for generating |
| 1700 | // instructions and relocation information. The constructor makes |
| 1701 | // sure that there is enough space and (in debug mode) the destructor |
| 1702 | // checks that we did not generate too much. |
| 1703 | class EnsureSpace BASE_EMBEDDED { |
| 1704 | public: |
| 1705 | explicit EnsureSpace(Assembler* assembler) : assembler_(assembler) { |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1706 | if (assembler_->buffer_overflow()) assembler_->GrowBuffer(); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1707 | #ifdef DEBUG |
| 1708 | space_before_ = assembler_->available_space(); |
| 1709 | #endif |
| 1710 | } |
| 1711 | |
| 1712 | #ifdef DEBUG |
| 1713 | ~EnsureSpace() { |
| 1714 | int bytes_generated = space_before_ - assembler_->available_space(); |
| 1715 | ASSERT(bytes_generated < assembler_->kGap); |
| 1716 | } |
| 1717 | #endif |
| 1718 | |
| 1719 | private: |
| 1720 | Assembler* assembler_; |
| 1721 | #ifdef DEBUG |
| 1722 | int space_before_; |
| 1723 | #endif |
| 1724 | }; |
| 1725 | |
| 1726 | } } // namespace v8::internal |
| 1727 | |
| 1728 | #endif // V8_X64_ASSEMBLER_X64_H_ |