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