| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_ASSEMBLER_X64_H_ | 5 #ifndef VM_ASSEMBLER_X64_H_ |
| 6 #define VM_ASSEMBLER_X64_H_ | 6 #define VM_ASSEMBLER_X64_H_ |
| 7 | 7 |
| 8 #ifndef VM_ASSEMBLER_H_ | 8 #ifndef VM_ASSEMBLER_H_ |
| 9 #error Do not include assembler_x64.h directly; use assembler.h instead. | 9 #error Do not include assembler_x64.h directly; use assembler.h instead. |
| 10 #endif | 10 #endif |
| 11 | 11 |
| 12 #include "platform/assert.h" | 12 #include "platform/assert.h" |
| 13 #include "platform/utils.h" | 13 #include "platform/utils.h" |
| 14 #include "vm/constants_x64.h" | 14 #include "vm/constants_x64.h" |
| 15 | 15 |
| 16 namespace dart { | 16 namespace dart { |
| 17 | 17 |
| 18 // Forward declarations. | 18 // Forward declarations. |
| 19 class RuntimeEntry; | 19 class RuntimeEntry; |
| 20 | 20 |
| 21 class Immediate : public ValueObject { | 21 class Immediate : public ValueObject { |
| 22 public: | 22 public: |
| 23 explicit Immediate(int64_t value) : value_(value) { } | 23 explicit Immediate(int64_t value) : value_(value) { } |
| 24 | 24 |
| 25 Immediate(const Immediate& other) : ValueObject(), value_(other.value_) { } |
| 26 |
| 25 int64_t value() const { return value_; } | 27 int64_t value() const { return value_; } |
| 26 | 28 |
| 27 bool is_int8() const { return Utils::IsInt(8, value_); } | 29 bool is_int8() const { return Utils::IsInt(8, value_); } |
| 28 bool is_uint8() const { return Utils::IsUint(8, value_); } | 30 bool is_uint8() const { return Utils::IsUint(8, value_); } |
| 29 bool is_uint16() const { return Utils::IsUint(16, value_); } | 31 bool is_uint16() const { return Utils::IsUint(16, value_); } |
| 30 bool is_int32() const { return Utils::IsInt(32, value_); } | 32 bool is_int32() const { return Utils::IsInt(32, value_); } |
| 31 | 33 |
| 32 private: | 34 private: |
| 33 const int64_t value_; | 35 const int64_t value_; |
| 34 | 36 |
| 35 // TODO(5411081): Add DISALLOW_COPY_AND_ASSIGN(Immediate) once the mac | 37 // TODO(5411081): Add DISALLOW_COPY_AND_ASSIGN(Immediate) once the mac |
| 36 // build issue is resolved. | 38 // build issue is resolved. |
| 39 // And remove the unnecessary copy constructor. |
| 37 }; | 40 }; |
| 38 | 41 |
| 39 | 42 |
| 40 class Operand : public ValueObject { | 43 class Operand : public ValueObject { |
| 41 public: | 44 public: |
| 42 uint8_t rex() const { | 45 uint8_t rex() const { |
| 43 return rex_; | 46 return rex_; |
| 44 } | 47 } |
| 45 | 48 |
| 46 uint8_t mod() const { | 49 uint8_t mod() const { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 69 int8_t disp8() const { | 72 int8_t disp8() const { |
| 70 ASSERT(length_ >= 2); | 73 ASSERT(length_ >= 2); |
| 71 return static_cast<int8_t>(encoding_[length_ - 1]); | 74 return static_cast<int8_t>(encoding_[length_ - 1]); |
| 72 } | 75 } |
| 73 | 76 |
| 74 int32_t disp32() const { | 77 int32_t disp32() const { |
| 75 ASSERT(length_ >= 5); | 78 ASSERT(length_ >= 5); |
| 76 return bit_copy<int32_t>(encoding_[length_ - 4]); | 79 return bit_copy<int32_t>(encoding_[length_ - 4]); |
| 77 } | 80 } |
| 78 | 81 |
| 82 Operand(const Operand& other) |
| 83 : ValueObject(), length_(other.length_), rex_(other.rex_) { |
| 84 memmove(&encoding_[0], &other.encoding_[0], other.length_); |
| 85 } |
| 86 |
| 87 Operand& operator=(const Operand& other) { |
| 88 length_ = other.length_; |
| 89 rex_ = other.rex_; |
| 90 memmove(&encoding_[0], &other.encoding_[0], other.length_); |
| 91 return *this; |
| 92 } |
| 93 |
| 79 protected: | 94 protected: |
| 80 Operand() : length_(0), rex_(REX_NONE) { } | 95 Operand() : length_(0), rex_(REX_NONE) { } // Needed by subclass Address. |
| 81 | 96 |
| 82 void SetModRM(int mod, Register rm) { | 97 void SetModRM(int mod, Register rm) { |
| 83 ASSERT((mod & ~3) == 0); | 98 ASSERT((mod & ~3) == 0); |
| 84 if ((rm > 7) && !((rm == R12) && (mod != 3))) { | 99 if ((rm > 7) && !((rm == R12) && (mod != 3))) { |
| 85 rex_ |= REX_B; | 100 rex_ |= REX_B; |
| 86 } | 101 } |
| 87 encoding_[0] = (mod << 6) | (rm & 7); | 102 encoding_[0] = (mod << 6) | (rm & 7); |
| 88 length_ = 1; | 103 length_ = 1; |
| 89 } | 104 } |
| 90 | 105 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } | 140 } |
| 126 | 141 |
| 127 // Returns whether or not this operand is really the given register in | 142 // Returns whether or not this operand is really the given register in |
| 128 // disguise. Used from the assembler to generate better encodings. | 143 // disguise. Used from the assembler to generate better encodings. |
| 129 bool IsRegister(Register reg) const { | 144 bool IsRegister(Register reg) const { |
| 130 return ((reg > 7 ? 1 : 0) == (rex_ & REX_B)) // REX.B match. | 145 return ((reg > 7 ? 1 : 0) == (rex_ & REX_B)) // REX.B match. |
| 131 && ((encoding_at(0) & 0xF8) == 0xC0) // Addressing mode is register. | 146 && ((encoding_at(0) & 0xF8) == 0xC0) // Addressing mode is register. |
| 132 && ((encoding_at(0) & 0x07) == reg); // Register codes match. | 147 && ((encoding_at(0) & 0x07) == reg); // Register codes match. |
| 133 } | 148 } |
| 134 | 149 |
| 135 | |
| 136 friend class Assembler; | 150 friend class Assembler; |
| 137 | |
| 138 // TODO(5411081): Add DISALLOW_COPY_AND_ASSIGN(Operand) once the mac | |
| 139 // build issue is resolved. | |
| 140 }; | 151 }; |
| 141 | 152 |
| 142 | 153 |
| 143 class Address : public Operand { | 154 class Address : public Operand { |
| 144 public: | 155 public: |
| 145 Address(Register base, int32_t disp) { | 156 Address(Register base, int32_t disp) { |
| 146 if ((disp == 0) && ((base & 7) != RBP)) { | 157 if ((disp == 0) && ((base & 7) != RBP)) { |
| 147 SetModRM(0, base); | 158 SetModRM(0, base); |
| 148 if ((base & 7) == RSP) { | 159 if ((base & 7) == RSP) { |
| 149 SetSIB(TIMES_1, RSP, base); | 160 SetSIB(TIMES_1, RSP, base); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 179 SetModRM(1, RSP); | 190 SetModRM(1, RSP); |
| 180 SetSIB(scale, index, base); | 191 SetSIB(scale, index, base); |
| 181 SetDisp8(disp); | 192 SetDisp8(disp); |
| 182 } else { | 193 } else { |
| 183 SetModRM(2, RSP); | 194 SetModRM(2, RSP); |
| 184 SetSIB(scale, index, base); | 195 SetSIB(scale, index, base); |
| 185 SetDisp32(disp); | 196 SetDisp32(disp); |
| 186 } | 197 } |
| 187 } | 198 } |
| 188 | 199 |
| 189 private: | 200 Address(const Address& other) : Operand(other) { } |
| 190 Address() {} | |
| 191 | 201 |
| 192 // TODO(5411081): Add DISALLOW_COPY_AND_ASSIGN(Address) once the mac | 202 Address& operator=(const Address& other) { |
| 193 // build issue is resolved. | 203 Operand::operator=(other); |
| 204 return *this; |
| 205 } |
| 194 }; | 206 }; |
| 195 | 207 |
| 196 | 208 |
| 197 class FieldAddress : public Address { | 209 class FieldAddress : public Address { |
| 198 public: | 210 public: |
| 199 FieldAddress(Register base, int32_t disp) | 211 FieldAddress(Register base, int32_t disp) |
| 200 : Address(base, disp - kHeapObjectTag) {} | 212 : Address(base, disp - kHeapObjectTag) { } |
| 213 |
| 201 FieldAddress(Register base, Register index, ScaleFactor scale, int32_t disp) | 214 FieldAddress(Register base, Register index, ScaleFactor scale, int32_t disp) |
| 202 : Address(base, index, scale, disp - kHeapObjectTag) {} | 215 : Address(base, index, scale, disp - kHeapObjectTag) { } |
| 216 |
| 217 FieldAddress(const FieldAddress& other) : Address(other) { } |
| 218 |
| 219 FieldAddress& operator=(const FieldAddress& other) { |
| 220 Address::operator=(other); |
| 221 return *this; |
| 222 } |
| 203 }; | 223 }; |
| 204 | 224 |
| 205 | 225 |
| 206 class Label : public ValueObject { | 226 class Label : public ValueObject { |
| 207 public: | 227 public: |
| 208 Label() : position_(0), unresolved_(0) { | 228 Label() : position_(0), unresolved_(0) { |
| 209 #ifdef DEBUG | 229 #ifdef DEBUG |
| 210 for (int i = 0; i < kMaxUnresolvedBranches; i++) { | 230 for (int i = 0; i < kMaxUnresolvedBranches; i++) { |
| 211 unresolved_near_positions_[i] = -1; | 231 unresolved_near_positions_[i] = -1; |
| 212 } | 232 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 DISALLOW_COPY_AND_ASSIGN(Label); | 291 DISALLOW_COPY_AND_ASSIGN(Label); |
| 272 }; | 292 }; |
| 273 | 293 |
| 274 | 294 |
| 275 class CPUFeatures : public AllStatic { | 295 class CPUFeatures : public AllStatic { |
| 276 public: | 296 public: |
| 277 static void InitOnce(); | 297 static void InitOnce(); |
| 278 // x64 always has at least SSE2. | 298 // x64 always has at least SSE2. |
| 279 static bool sse2_supported() { return true; } | 299 static bool sse2_supported() { return true; } |
| 280 static bool sse4_1_supported(); | 300 static bool sse4_1_supported(); |
| 301 static bool double_truncate_round_supported() { return sse4_1_supported(); } |
| 281 | 302 |
| 282 private: | 303 private: |
| 283 static const uint64_t kSSE4_1BitMask = static_cast<uint64_t>(1) << 51; | 304 static const uint64_t kSSE4_1BitMask = static_cast<uint64_t>(1) << 51; |
| 284 | 305 |
| 285 static bool sse4_1_supported_; | 306 static bool sse4_1_supported_; |
| 286 #ifdef DEBUG | 307 #ifdef DEBUG |
| 287 static bool initialized_; | 308 static bool initialized_; |
| 288 #endif | 309 #endif |
| 289 }; | 310 }; |
| 290 | 311 |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 // Debugging and bringup support. | 670 // Debugging and bringup support. |
| 650 void Stop(const char* message); | 671 void Stop(const char* message); |
| 651 void Unimplemented(const char* message); | 672 void Unimplemented(const char* message); |
| 652 void Untested(const char* message); | 673 void Untested(const char* message); |
| 653 void Unreachable(const char* message); | 674 void Unreachable(const char* message); |
| 654 | 675 |
| 655 static void InitializeMemoryWithBreakpoints(uword data, int length); | 676 static void InitializeMemoryWithBreakpoints(uword data, int length); |
| 656 | 677 |
| 657 static const char* RegisterName(Register reg); | 678 static const char* RegisterName(Register reg); |
| 658 | 679 |
| 659 static const char* XmmRegisterName(XmmRegister reg); | 680 static const char* FpuRegisterName(FpuRegister reg); |
| 660 | 681 |
| 661 private: | 682 private: |
| 662 AssemblerBuffer buffer_; | 683 AssemblerBuffer buffer_; |
| 663 int prologue_offset_; | 684 int prologue_offset_; |
| 664 | 685 |
| 665 class CodeComment : public ZoneAllocated { | 686 class CodeComment : public ZoneAllocated { |
| 666 public: | 687 public: |
| 667 CodeComment(intptr_t pc_offset, const String& comment) | 688 CodeComment(intptr_t pc_offset, const String& comment) |
| 668 : pc_offset_(pc_offset), comment_(comment) { } | 689 : pc_offset_(pc_offset), comment_(comment) { } |
| 669 | 690 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 } | 810 } |
| 790 | 811 |
| 791 | 812 |
| 792 inline void Assembler::EmitOperandSizeOverride() { | 813 inline void Assembler::EmitOperandSizeOverride() { |
| 793 EmitUint8(0x66); | 814 EmitUint8(0x66); |
| 794 } | 815 } |
| 795 | 816 |
| 796 } // namespace dart | 817 } // namespace dart |
| 797 | 818 |
| 798 #endif // VM_ASSEMBLER_X64_H_ | 819 #endif // VM_ASSEMBLER_X64_H_ |
| OLD | NEW |