| 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_IA32_H_ | 5 #ifndef VM_ASSEMBLER_IA32_H_ |
| 6 #define VM_ASSEMBLER_IA32_H_ | 6 #define VM_ASSEMBLER_IA32_H_ |
| 7 | 7 |
| 8 #ifndef VM_ASSEMBLER_H_ | 8 #ifndef VM_ASSEMBLER_H_ |
| 9 #error Do not include assembler_ia32.h directly; use assembler.h instead. | 9 #error Do not include assembler_ia32.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_ia32.h" | 14 #include "vm/constants_ia32.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 { |
| 22 public: | 22 public: |
| 23 explicit Immediate(int32_t value) : value_(value) { } | 23 explicit Immediate(int32_t value) : value_(value) { } |
| 24 | 24 |
| 25 Immediate(const Immediate& other) : value_(other.value_) { } |
| 26 |
| 25 int32_t value() const { return value_; } | 27 int32_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 | 32 |
| 31 private: | 33 private: |
| 32 const int32_t value_; | 34 const int32_t value_; |
| 33 | 35 DISALLOW_ALLOCATION(); |
| 34 // TODO(5411081): Add DISALLOW_COPY_AND_ASSIGN(Immediate) once the mac | |
| 35 // build issue is resolved. | |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 | 38 |
| 39 class Operand : public ValueObject { | 39 class Operand { |
| 40 public: | 40 public: |
| 41 uint8_t mod() const { | 41 uint8_t mod() const { |
| 42 return (encoding_at(0) >> 6) & 3; | 42 return (encoding_at(0) >> 6) & 3; |
| 43 } | 43 } |
| 44 | 44 |
| 45 Register rm() const { | 45 Register rm() const { |
| 46 return static_cast<Register>(encoding_at(0) & 7); | 46 return static_cast<Register>(encoding_at(0) & 7); |
| 47 } | 47 } |
| 48 | 48 |
| 49 ScaleFactor scale() const { | 49 ScaleFactor scale() const { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 61 int8_t disp8() const { | 61 int8_t disp8() const { |
| 62 ASSERT(length_ >= 2); | 62 ASSERT(length_ >= 2); |
| 63 return static_cast<int8_t>(encoding_[length_ - 1]); | 63 return static_cast<int8_t>(encoding_[length_ - 1]); |
| 64 } | 64 } |
| 65 | 65 |
| 66 int32_t disp32() const { | 66 int32_t disp32() const { |
| 67 ASSERT(length_ >= 5); | 67 ASSERT(length_ >= 5); |
| 68 return bit_copy<int32_t>(encoding_[length_ - 4]); | 68 return bit_copy<int32_t>(encoding_[length_ - 4]); |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool IsRegister(Register reg) const { | 71 Operand(const Operand& other) : length_(other.length_) { |
| 72 return ((encoding_[0] & 0xF8) == 0xC0) // Addressing mode is register only. | 72 memmove(&encoding_[0], &other.encoding_[0], other.length_); |
| 73 && ((encoding_[0] & 0x07) == reg); // Register codes match. | 73 } |
| 74 |
| 75 Operand& operator=(const Operand& other) { |
| 76 length_ = other.length_; |
| 77 memmove(&encoding_[0], &other.encoding_[0], other.length_); |
| 78 return *this; |
| 74 } | 79 } |
| 75 | 80 |
| 76 protected: | 81 protected: |
| 77 // Operand can be sub classed (e.g: Address). | 82 Operand() : length_(0) { } // Needed by subclass Address. |
| 78 Operand() : length_(0) { } | |
| 79 | 83 |
| 80 void SetModRM(int mod, Register rm) { | 84 void SetModRM(int mod, Register rm) { |
| 81 ASSERT((mod & ~3) == 0); | 85 ASSERT((mod & ~3) == 0); |
| 82 encoding_[0] = (mod << 6) | rm; | 86 encoding_[0] = (mod << 6) | rm; |
| 83 length_ = 1; | 87 length_ = 1; |
| 84 } | 88 } |
| 85 | 89 |
| 86 void SetSIB(ScaleFactor scale, Register index, Register base) { | 90 void SetSIB(ScaleFactor scale, Register index, Register base) { |
| 87 ASSERT(length_ == 1); | 91 ASSERT(length_ == 1); |
| 88 ASSERT((scale & ~3) == 0); | 92 ASSERT((scale & ~3) == 0); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 108 uint8_t padding_; | 112 uint8_t padding_; |
| 109 | 113 |
| 110 explicit Operand(Register reg) { SetModRM(3, reg); } | 114 explicit Operand(Register reg) { SetModRM(3, reg); } |
| 111 | 115 |
| 112 // Get the operand encoding byte at the given index. | 116 // Get the operand encoding byte at the given index. |
| 113 uint8_t encoding_at(int index) const { | 117 uint8_t encoding_at(int index) const { |
| 114 ASSERT(index >= 0 && index < length_); | 118 ASSERT(index >= 0 && index < length_); |
| 115 return encoding_[index]; | 119 return encoding_[index]; |
| 116 } | 120 } |
| 117 | 121 |
| 122 // Returns whether or not this operand is really the given register in |
| 123 // disguise. Used from the assembler to generate better encodings. |
| 124 bool IsRegister(Register reg) const { |
| 125 return ((encoding_[0] & 0xF8) == 0xC0) // Addressing mode is register only. |
| 126 && ((encoding_[0] & 0x07) == reg); // Register codes match. |
| 127 } |
| 128 |
| 118 friend class Assembler; | 129 friend class Assembler; |
| 119 | 130 DISALLOW_ALLOCATION(); |
| 120 // TODO(5411081): Add DISALLOW_COPY_AND_ASSIGN(Operand) once the mac | |
| 121 // build issue is resolved. | |
| 122 }; | 131 }; |
| 123 | 132 |
| 124 | 133 |
| 125 class Address : public Operand { | 134 class Address : public Operand { |
| 126 public: | 135 public: |
| 127 Address(Register base, int32_t disp) { | 136 Address(Register base, int32_t disp) { |
| 128 if (disp == 0 && base != EBP) { | 137 if (disp == 0 && base != EBP) { |
| 129 SetModRM(0, base); | 138 SetModRM(0, base); |
| 130 if (base == ESP) SetSIB(TIMES_1, ESP, base); | 139 if (base == ESP) SetSIB(TIMES_1, ESP, base); |
| 131 } else if (Utils::IsInt(8, disp)) { | 140 } else if (Utils::IsInt(8, disp)) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 155 SetModRM(1, ESP); | 164 SetModRM(1, ESP); |
| 156 SetSIB(scale, index, base); | 165 SetSIB(scale, index, base); |
| 157 SetDisp8(disp); | 166 SetDisp8(disp); |
| 158 } else { | 167 } else { |
| 159 SetModRM(2, ESP); | 168 SetModRM(2, ESP); |
| 160 SetSIB(scale, index, base); | 169 SetSIB(scale, index, base); |
| 161 SetDisp32(disp); | 170 SetDisp32(disp); |
| 162 } | 171 } |
| 163 } | 172 } |
| 164 | 173 |
| 174 Address(const Address& other) : Operand(other) { } |
| 175 |
| 176 Address& operator=(const Address& other) { |
| 177 Operand::operator=(other); |
| 178 return *this; |
| 179 } |
| 180 |
| 165 static Address Absolute(const uword addr) { | 181 static Address Absolute(const uword addr) { |
| 166 Address result; | 182 Address result; |
| 167 result.SetModRM(0, EBP); | 183 result.SetModRM(0, EBP); |
| 168 result.SetDisp32(addr); | 184 result.SetDisp32(addr); |
| 169 return result; | 185 return result; |
| 170 } | 186 } |
| 171 | 187 |
| 172 private: | 188 private: |
| 173 Address() {} | 189 Address() { } // Needed by Address::Absolute. |
| 174 | |
| 175 // TODO(5411081): Add DISALLOW_COPY_AND_ASSIGN(Address) once the mac | |
| 176 // build issue is resolved. | |
| 177 }; | 190 }; |
| 178 | 191 |
| 179 | 192 |
| 180 class FieldAddress : public Address { | 193 class FieldAddress : public Address { |
| 181 public: | 194 public: |
| 182 FieldAddress(Register base, int32_t disp) | 195 FieldAddress(Register base, int32_t disp) |
| 183 : Address(base, disp - kHeapObjectTag) {} | 196 : Address(base, disp - kHeapObjectTag) { } |
| 197 |
| 184 FieldAddress(Register base, Register index, ScaleFactor scale, int32_t disp) | 198 FieldAddress(Register base, Register index, ScaleFactor scale, int32_t disp) |
| 185 : Address(base, index, scale, disp - kHeapObjectTag) {} | 199 : Address(base, index, scale, disp - kHeapObjectTag) { } |
| 200 |
| 201 FieldAddress(const FieldAddress& other) : Address(other) { } |
| 202 |
| 203 FieldAddress& operator=(const FieldAddress& other) { |
| 204 Address::operator=(other); |
| 205 return *this; |
| 206 } |
| 186 }; | 207 }; |
| 187 | 208 |
| 188 | 209 |
| 189 class Label : public ValueObject { | 210 class Label : public ValueObject { |
| 190 public: | 211 public: |
| 191 Label() : position_(0), unresolved_(0) { | 212 Label() : position_(0), unresolved_(0) { |
| 192 #ifdef DEBUG | 213 #ifdef DEBUG |
| 193 for (int i = 0; i < kMaxUnresolvedBranches; i++) { | 214 for (int i = 0; i < kMaxUnresolvedBranches; i++) { |
| 194 unresolved_near_positions_[i] = -1; | 215 unresolved_near_positions_[i] = -1; |
| 195 } | 216 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 friend class Assembler; | 274 friend class Assembler; |
| 254 DISALLOW_COPY_AND_ASSIGN(Label); | 275 DISALLOW_COPY_AND_ASSIGN(Label); |
| 255 }; | 276 }; |
| 256 | 277 |
| 257 | 278 |
| 258 class CPUFeatures : public AllStatic { | 279 class CPUFeatures : public AllStatic { |
| 259 public: | 280 public: |
| 260 static void InitOnce(); | 281 static void InitOnce(); |
| 261 static bool sse2_supported(); | 282 static bool sse2_supported(); |
| 262 static bool sse4_1_supported(); | 283 static bool sse4_1_supported(); |
| 284 static bool double_truncate_round_supported() { return sse4_1_supported(); } |
| 263 | 285 |
| 264 private: | 286 private: |
| 265 static const uint64_t kSSE2BitMask = static_cast<uint64_t>(1) << 26; | 287 static const uint64_t kSSE2BitMask = static_cast<uint64_t>(1) << 26; |
| 266 static const uint64_t kSSE4_1BitMask = static_cast<uint64_t>(1) << 51; | 288 static const uint64_t kSSE4_1BitMask = static_cast<uint64_t>(1) << 51; |
| 267 | 289 |
| 268 static bool sse2_supported_; | 290 static bool sse2_supported_; |
| 269 static bool sse4_1_supported_; | 291 static bool sse4_1_supported_; |
| 270 #ifdef DEBUG | 292 #ifdef DEBUG |
| 271 static bool initialized_; | 293 static bool initialized_; |
| 272 #endif | 294 #endif |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 void Unimplemented(const char* message); | 651 void Unimplemented(const char* message); |
| 630 void Untested(const char* message); | 652 void Untested(const char* message); |
| 631 void Unreachable(const char* message); | 653 void Unreachable(const char* message); |
| 632 | 654 |
| 633 static void InitializeMemoryWithBreakpoints(uword data, int length); | 655 static void InitializeMemoryWithBreakpoints(uword data, int length); |
| 634 | 656 |
| 635 void Comment(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); | 657 void Comment(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); |
| 636 const Code::Comments& GetCodeComments() const; | 658 const Code::Comments& GetCodeComments() const; |
| 637 | 659 |
| 638 static const char* RegisterName(Register reg); | 660 static const char* RegisterName(Register reg); |
| 639 static const char* XmmRegisterName(XmmRegister reg); | 661 static const char* FpuRegisterName(FpuRegister reg); |
| 640 | 662 |
| 641 private: | 663 private: |
| 642 AssemblerBuffer buffer_; | 664 AssemblerBuffer buffer_; |
| 643 int prologue_offset_; | 665 int prologue_offset_; |
| 644 | 666 |
| 645 class CodeComment : public ZoneAllocated { | 667 class CodeComment : public ZoneAllocated { |
| 646 public: | 668 public: |
| 647 CodeComment(intptr_t pc_offset, const String& comment) | 669 CodeComment(intptr_t pc_offset, const String& comment) |
| 648 : pc_offset_(pc_offset), comment_(comment) { } | 670 : pc_offset_(pc_offset), comment_(comment) { } |
| 649 | 671 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 } | 731 } |
| 710 | 732 |
| 711 | 733 |
| 712 inline void Assembler::EmitOperandSizeOverride() { | 734 inline void Assembler::EmitOperandSizeOverride() { |
| 713 EmitUint8(0x66); | 735 EmitUint8(0x66); |
| 714 } | 736 } |
| 715 | 737 |
| 716 } // namespace dart | 738 } // namespace dart |
| 717 | 739 |
| 718 #endif // VM_ASSEMBLER_IA32_H_ | 740 #endif // VM_ASSEMBLER_IA32_H_ |
| OLD | NEW |