| OLD | NEW |
| 1 // Copyright (c) 1994-2006 Sun Microsystems Inc. | 1 // Copyright (c) 1994-2006 Sun Microsystems Inc. |
| 2 // All Rights Reserved. | 2 // All Rights Reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // - Redistributions of source code must retain the above copyright notice, | 8 // - Redistributions of source code must retain the above copyright notice, |
| 9 // this list of conditions and the following disclaimer. | 9 // this list of conditions and the following disclaimer. |
| 10 // | 10 // |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 23 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 24 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 24 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 25 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 25 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 26 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | 26 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 27 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | 27 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 28 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 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. | 29 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | 30 |
| 31 // The original source code covered by the above license above has been | 31 // The original source code covered by the above license above has been |
| 32 // modified significantly by Google Inc. | 32 // modified significantly by Google Inc. |
| 33 // Copyright 2010 the V8 project authors. All rights reserved. | 33 // Copyright 2011 the V8 project authors. All rights reserved. |
| 34 | 34 |
| 35 // A lightweight X64 Assembler. | 35 // A lightweight X64 Assembler. |
| 36 | 36 |
| 37 #ifndef V8_X64_ASSEMBLER_X64_H_ | 37 #ifndef V8_X64_ASSEMBLER_X64_H_ |
| 38 #define V8_X64_ASSEMBLER_X64_H_ | 38 #define V8_X64_ASSEMBLER_X64_H_ |
| 39 | 39 |
| 40 #include "serialize.h" | 40 #include "serialize.h" |
| 41 | 41 |
| 42 namespace v8 { | 42 namespace v8 { |
| 43 namespace internal { | 43 namespace internal { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 // rsp - stack pointer | 92 // rsp - stack pointer |
| 93 // rbp - frame pointer | 93 // rbp - frame pointer |
| 94 // rsi - context register | 94 // rsi - context register |
| 95 // r10 - fixed scratch register | 95 // r10 - fixed scratch register |
| 96 // r13 - root register | 96 // r13 - root register |
| 97 // r15 - smi constant register | 97 // r15 - smi constant register |
| 98 static const int kNumRegisters = 16; | 98 static const int kNumRegisters = 16; |
| 99 static const int kNumAllocatableRegisters = 10; | 99 static const int kNumAllocatableRegisters = 10; |
| 100 | 100 |
| 101 static int ToAllocationIndex(Register reg) { | 101 static int ToAllocationIndex(Register reg) { |
| 102 return allocationIndexByRegisterCode[reg.code()]; | 102 return kAllocationIndexByRegisterCode[reg.code()]; |
| 103 } | 103 } |
| 104 | 104 |
| 105 static Register FromAllocationIndex(int index) { | 105 static Register FromAllocationIndex(int index) { |
| 106 ASSERT(index >= 0 && index < kNumAllocatableRegisters); | 106 ASSERT(index >= 0 && index < kNumAllocatableRegisters); |
| 107 Register result = { registerCodeByAllocationIndex[index] }; | 107 Register result = { kRegisterCodeByAllocationIndex[index] }; |
| 108 return result; | 108 return result; |
| 109 } | 109 } |
| 110 | 110 |
| 111 static const char* AllocationIndexToString(int index) { | 111 static const char* AllocationIndexToString(int index) { |
| 112 ASSERT(index >= 0 && index < kNumAllocatableRegisters); | 112 ASSERT(index >= 0 && index < kNumAllocatableRegisters); |
| 113 const char* const names[] = { | 113 const char* const names[] = { |
| 114 "rax", | 114 "rax", |
| 115 "rbx", | 115 "rbx", |
| 116 "rdx", | 116 "rdx", |
| 117 "rcx", | 117 "rcx", |
| (...skipping 30 matching lines...) Expand all Loading... |
| 148 // in modR/M, SIB, and opcode bytes. | 148 // in modR/M, SIB, and opcode bytes. |
| 149 int low_bits() const { | 149 int low_bits() const { |
| 150 return code_ & 0x7; | 150 return code_ & 0x7; |
| 151 } | 151 } |
| 152 | 152 |
| 153 // Unfortunately we can't make this private in a struct when initializing | 153 // Unfortunately we can't make this private in a struct when initializing |
| 154 // by assignment. | 154 // by assignment. |
| 155 int code_; | 155 int code_; |
| 156 | 156 |
| 157 private: | 157 private: |
| 158 static const int registerCodeByAllocationIndex[kNumAllocatableRegisters]; | 158 static const int kRegisterCodeByAllocationIndex[kNumAllocatableRegisters]; |
| 159 static const int allocationIndexByRegisterCode[kNumRegisters]; | 159 static const int kAllocationIndexByRegisterCode[kNumRegisters]; |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 const Register rax = { 0 }; | 162 const Register rax = { 0 }; |
| 163 const Register rcx = { 1 }; | 163 const Register rcx = { 1 }; |
| 164 const Register rdx = { 2 }; | 164 const Register rdx = { 2 }; |
| 165 const Register rbx = { 3 }; | 165 const Register rbx = { 3 }; |
| 166 const Register rsp = { 4 }; | 166 const Register rsp = { 4 }; |
| 167 const Register rbp = { 5 }; | 167 const Register rbp = { 5 }; |
| 168 const Register rsi = { 6 }; | 168 const Register rsi = { 6 }; |
| 169 const Register rdi = { 7 }; | 169 const Register rdi = { 7 }; |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 static const int kJSReturnSequenceLength = 13; | 578 static const int kJSReturnSequenceLength = 13; |
| 579 static const int kShortCallInstructionLength = 5; | 579 static const int kShortCallInstructionLength = 5; |
| 580 | 580 |
| 581 // The debug break slot must be able to contain a call instruction. | 581 // The debug break slot must be able to contain a call instruction. |
| 582 static const int kDebugBreakSlotLength = kCallInstructionLength; | 582 static const int kDebugBreakSlotLength = kCallInstructionLength; |
| 583 | 583 |
| 584 // One byte opcode for test eax,0xXXXXXXXX. | 584 // One byte opcode for test eax,0xXXXXXXXX. |
| 585 static const byte kTestEaxByte = 0xA9; | 585 static const byte kTestEaxByte = 0xA9; |
| 586 // One byte opcode for test al, 0xXX. | 586 // One byte opcode for test al, 0xXX. |
| 587 static const byte kTestAlByte = 0xA8; | 587 static const byte kTestAlByte = 0xA8; |
| 588 // One byte opcode for nop. |
| 589 static const byte kNopByte = 0x90; |
| 590 |
| 591 // One byte prefix for a short conditional jump. |
| 592 static const byte kJccShortPrefix = 0x70; |
| 593 static const byte kJncShortOpcode = kJccShortPrefix | not_carry; |
| 594 static const byte kJcShortOpcode = kJccShortPrefix | carry; |
| 595 |
| 596 |
| 588 | 597 |
| 589 // --------------------------------------------------------------------------- | 598 // --------------------------------------------------------------------------- |
| 590 // Code generation | 599 // Code generation |
| 591 // | 600 // |
| 592 // Function names correspond one-to-one to x64 instruction mnemonics. | 601 // Function names correspond one-to-one to x64 instruction mnemonics. |
| 593 // Unless specified otherwise, instructions operate on 64-bit operands. | 602 // Unless specified otherwise, instructions operate on 64-bit operands. |
| 594 // | 603 // |
| 595 // If we need versions of an assembly instruction that operate on different | 604 // If we need versions of an assembly instruction that operate on different |
| 596 // width arguments, we add a single-letter suffix specifying the width. | 605 // width arguments, we add a single-letter suffix specifying the width. |
| 597 // This is done for the following instructions: mov, cmp, inc, dec, | 606 // This is done for the following instructions: mov, cmp, inc, dec, |
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1286 void cvtsd2ss(XMMRegister dst, XMMRegister src); | 1295 void cvtsd2ss(XMMRegister dst, XMMRegister src); |
| 1287 | 1296 |
| 1288 void cvtsd2si(Register dst, XMMRegister src); | 1297 void cvtsd2si(Register dst, XMMRegister src); |
| 1289 void cvtsd2siq(Register dst, XMMRegister src); | 1298 void cvtsd2siq(Register dst, XMMRegister src); |
| 1290 | 1299 |
| 1291 void addsd(XMMRegister dst, XMMRegister src); | 1300 void addsd(XMMRegister dst, XMMRegister src); |
| 1292 void subsd(XMMRegister dst, XMMRegister src); | 1301 void subsd(XMMRegister dst, XMMRegister src); |
| 1293 void mulsd(XMMRegister dst, XMMRegister src); | 1302 void mulsd(XMMRegister dst, XMMRegister src); |
| 1294 void divsd(XMMRegister dst, XMMRegister src); | 1303 void divsd(XMMRegister dst, XMMRegister src); |
| 1295 | 1304 |
| 1305 void andpd(XMMRegister dst, XMMRegister src); |
| 1306 void orpd(XMMRegister dst, XMMRegister src); |
| 1296 void xorpd(XMMRegister dst, XMMRegister src); | 1307 void xorpd(XMMRegister dst, XMMRegister src); |
| 1297 void sqrtsd(XMMRegister dst, XMMRegister src); | 1308 void sqrtsd(XMMRegister dst, XMMRegister src); |
| 1298 | 1309 |
| 1299 void ucomisd(XMMRegister dst, XMMRegister src); | 1310 void ucomisd(XMMRegister dst, XMMRegister src); |
| 1300 void ucomisd(XMMRegister dst, const Operand& src); | 1311 void ucomisd(XMMRegister dst, const Operand& src); |
| 1301 | 1312 |
| 1302 void movmskpd(Register dst, XMMRegister src); | 1313 void movmskpd(Register dst, XMMRegister src); |
| 1303 | 1314 |
| 1304 // The first argument is the reg field, the second argument is the r/m field. | 1315 // The first argument is the reg field, the second argument is the r/m field. |
| 1305 void emit_sse_operand(XMMRegister dst, XMMRegister src); | 1316 void emit_sse_operand(XMMRegister dst, XMMRegister src); |
| 1306 void emit_sse_operand(XMMRegister reg, const Operand& adr); | 1317 void emit_sse_operand(XMMRegister reg, const Operand& adr); |
| 1307 void emit_sse_operand(XMMRegister dst, Register src); | 1318 void emit_sse_operand(XMMRegister dst, Register src); |
| 1308 void emit_sse_operand(Register dst, XMMRegister src); | 1319 void emit_sse_operand(Register dst, XMMRegister src); |
| 1309 | 1320 |
| 1310 // Debugging | 1321 // Debugging |
| 1311 void Print(); | 1322 void Print(); |
| 1312 | 1323 |
| 1313 // Check the code size generated from label to here. | 1324 // Check the code size generated from label to here. |
| 1314 int SizeOfCodeGeneratedSince(Label* l) { return pc_offset() - l->pos(); } | 1325 int SizeOfCodeGeneratedSince(Label* l) { return pc_offset() - l->pos(); } |
| 1315 | 1326 |
| 1316 // Mark address of the ExitJSFrame code. | 1327 // Mark address of the ExitJSFrame code. |
| 1317 void RecordJSReturn(); | 1328 void RecordJSReturn(); |
| 1318 | 1329 |
| 1319 // Mark address of a debug break slot. | 1330 // Mark address of a debug break slot. |
| 1320 void RecordDebugBreakSlot(); | 1331 void RecordDebugBreakSlot(); |
| 1321 | 1332 |
| 1322 // Record a comment relocation entry that can be used by a disassembler. | 1333 // Record a comment relocation entry that can be used by a disassembler. |
| 1323 // Use --code-comments to enable. | 1334 // Use --code-comments to enable. |
| 1324 void RecordComment(const char* msg); | 1335 void RecordComment(const char* msg, bool force = false); |
| 1325 | 1336 |
| 1326 // Writes a single word of data in the code stream. | 1337 // Writes a single word of data in the code stream. |
| 1327 // Used for inline tables, e.g., jump-tables. | 1338 // Used for inline tables, e.g., jump-tables. |
| 1328 void db(uint8_t data); | 1339 void db(uint8_t data); |
| 1329 void dd(uint32_t data); | 1340 void dd(uint32_t data); |
| 1330 | 1341 |
| 1331 int pc_offset() const { return static_cast<int>(pc_ - buffer_); } | 1342 int pc_offset() const { return static_cast<int>(pc_ - buffer_); } |
| 1332 | 1343 |
| 1333 PositionsRecorder* positions_recorder() { return &positions_recorder_; } | 1344 PositionsRecorder* positions_recorder() { return &positions_recorder_; } |
| 1334 | 1345 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1580 private: | 1591 private: |
| 1581 Assembler* assembler_; | 1592 Assembler* assembler_; |
| 1582 #ifdef DEBUG | 1593 #ifdef DEBUG |
| 1583 int space_before_; | 1594 int space_before_; |
| 1584 #endif | 1595 #endif |
| 1585 }; | 1596 }; |
| 1586 | 1597 |
| 1587 } } // namespace v8::internal | 1598 } } // namespace v8::internal |
| 1588 | 1599 |
| 1589 #endif // V8_X64_ASSEMBLER_X64_H_ | 1600 #endif // V8_X64_ASSEMBLER_X64_H_ |
| OLD | NEW |