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 { |
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) : 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 DISALLOW_ALLOCATION() |
35 // TODO(5411081): Add DISALLOW_COPY_AND_ASSIGN(Immediate) once the mac | |
36 // build issue is resolved. | |
37 }; | 37 }; |
38 | 38 |
39 | 39 |
40 class Operand : public ValueObject { | 40 class Operand { |
41 public: | 41 public: |
42 uint8_t rex() const { | 42 uint8_t rex() const { |
43 return rex_; | 43 return rex_; |
44 } | 44 } |
45 | 45 |
46 uint8_t mod() const { | 46 uint8_t mod() const { |
47 return (encoding_at(0) >> 6) & 3; | 47 return (encoding_at(0) >> 6) & 3; |
48 } | 48 } |
49 | 49 |
50 Register rm() const { | 50 Register rm() const { |
(...skipping 18 matching lines...) Expand all Loading... |
69 int8_t disp8() const { | 69 int8_t disp8() const { |
70 ASSERT(length_ >= 2); | 70 ASSERT(length_ >= 2); |
71 return static_cast<int8_t>(encoding_[length_ - 1]); | 71 return static_cast<int8_t>(encoding_[length_ - 1]); |
72 } | 72 } |
73 | 73 |
74 int32_t disp32() const { | 74 int32_t disp32() const { |
75 ASSERT(length_ >= 5); | 75 ASSERT(length_ >= 5); |
76 return bit_copy<int32_t>(encoding_[length_ - 4]); | 76 return bit_copy<int32_t>(encoding_[length_ - 4]); |
77 } | 77 } |
78 | 78 |
| 79 Operand(const Operand& other) : length_(other.length_), rex_(other.rex_) { |
| 80 memmove(&encoding_[0], &other.encoding_[0], other.length_); |
| 81 } |
| 82 |
| 83 Operand& operator=(const Operand& other) { |
| 84 length_ = other.length_; |
| 85 rex_ = other.rex_; |
| 86 memmove(&encoding_[0], &other.encoding_[0], other.length_); |
| 87 return *this; |
| 88 } |
| 89 |
79 protected: | 90 protected: |
80 Operand() : length_(0), rex_(REX_NONE) { } | 91 Operand() : length_(0), rex_(REX_NONE) { } // Needed by subclass Address. |
81 | 92 |
82 void SetModRM(int mod, Register rm) { | 93 void SetModRM(int mod, Register rm) { |
83 ASSERT((mod & ~3) == 0); | 94 ASSERT((mod & ~3) == 0); |
84 if ((rm > 7) && !((rm == R12) && (mod != 3))) { | 95 if ((rm > 7) && !((rm == R12) && (mod != 3))) { |
85 rex_ |= REX_B; | 96 rex_ |= REX_B; |
86 } | 97 } |
87 encoding_[0] = (mod << 6) | (rm & 7); | 98 encoding_[0] = (mod << 6) | (rm & 7); |
88 length_ = 1; | 99 length_ = 1; |
89 } | 100 } |
90 | 101 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 136 } |
126 | 137 |
127 // Returns whether or not this operand is really the given register in | 138 // Returns whether or not this operand is really the given register in |
128 // disguise. Used from the assembler to generate better encodings. | 139 // disguise. Used from the assembler to generate better encodings. |
129 bool IsRegister(Register reg) const { | 140 bool IsRegister(Register reg) const { |
130 return ((reg > 7 ? 1 : 0) == (rex_ & REX_B)) // REX.B match. | 141 return ((reg > 7 ? 1 : 0) == (rex_ & REX_B)) // REX.B match. |
131 && ((encoding_at(0) & 0xF8) == 0xC0) // Addressing mode is register. | 142 && ((encoding_at(0) & 0xF8) == 0xC0) // Addressing mode is register. |
132 && ((encoding_at(0) & 0x07) == reg); // Register codes match. | 143 && ((encoding_at(0) & 0x07) == reg); // Register codes match. |
133 } | 144 } |
134 | 145 |
135 | |
136 friend class Assembler; | 146 friend class Assembler; |
137 | 147 DISALLOW_ALLOCATION() |
138 // TODO(5411081): Add DISALLOW_COPY_AND_ASSIGN(Operand) once the mac | |
139 // build issue is resolved. | |
140 }; | 148 }; |
141 | 149 |
142 | 150 |
143 class Address : public Operand { | 151 class Address : public Operand { |
144 public: | 152 public: |
145 Address(Register base, int32_t disp) { | 153 Address(Register base, int32_t disp) { |
146 if ((disp == 0) && ((base & 7) != RBP)) { | 154 if ((disp == 0) && ((base & 7) != RBP)) { |
147 SetModRM(0, base); | 155 SetModRM(0, base); |
148 if ((base & 7) == RSP) { | 156 if ((base & 7) == RSP) { |
149 SetSIB(TIMES_1, RSP, base); | 157 SetSIB(TIMES_1, RSP, base); |
(...skipping 29 matching lines...) Expand all Loading... |
179 SetModRM(1, RSP); | 187 SetModRM(1, RSP); |
180 SetSIB(scale, index, base); | 188 SetSIB(scale, index, base); |
181 SetDisp8(disp); | 189 SetDisp8(disp); |
182 } else { | 190 } else { |
183 SetModRM(2, RSP); | 191 SetModRM(2, RSP); |
184 SetSIB(scale, index, base); | 192 SetSIB(scale, index, base); |
185 SetDisp32(disp); | 193 SetDisp32(disp); |
186 } | 194 } |
187 } | 195 } |
188 | 196 |
189 private: | 197 Address(const Address& other) : Operand(other) { } |
190 Address() {} | |
191 | 198 |
192 // TODO(5411081): Add DISALLOW_COPY_AND_ASSIGN(Address) once the mac | 199 Address& operator=(const Address& other) { |
193 // build issue is resolved. | 200 Operand::operator=(other); |
| 201 return *this; |
| 202 } |
194 }; | 203 }; |
195 | 204 |
196 | 205 |
197 class FieldAddress : public Address { | 206 class FieldAddress : public Address { |
198 public: | 207 public: |
199 FieldAddress(Register base, int32_t disp) | 208 FieldAddress(Register base, int32_t disp) |
200 : Address(base, disp - kHeapObjectTag) {} | 209 : Address(base, disp - kHeapObjectTag) { } |
| 210 |
201 FieldAddress(Register base, Register index, ScaleFactor scale, int32_t disp) | 211 FieldAddress(Register base, Register index, ScaleFactor scale, int32_t disp) |
202 : Address(base, index, scale, disp - kHeapObjectTag) {} | 212 : Address(base, index, scale, disp - kHeapObjectTag) { } |
| 213 |
| 214 FieldAddress(const FieldAddress& other) : Address(other) { } |
| 215 |
| 216 FieldAddress& operator=(const FieldAddress& other) { |
| 217 Address::operator=(other); |
| 218 return *this; |
| 219 } |
203 }; | 220 }; |
204 | 221 |
205 | 222 |
206 class Label : public ValueObject { | 223 class Label : public ValueObject { |
207 public: | 224 public: |
208 Label() : position_(0), unresolved_(0) { | 225 Label() : position_(0), unresolved_(0) { |
209 #ifdef DEBUG | 226 #ifdef DEBUG |
210 for (int i = 0; i < kMaxUnresolvedBranches; i++) { | 227 for (int i = 0; i < kMaxUnresolvedBranches; i++) { |
211 unresolved_near_positions_[i] = -1; | 228 unresolved_near_positions_[i] = -1; |
212 } | 229 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 DISALLOW_COPY_AND_ASSIGN(Label); | 288 DISALLOW_COPY_AND_ASSIGN(Label); |
272 }; | 289 }; |
273 | 290 |
274 | 291 |
275 class CPUFeatures : public AllStatic { | 292 class CPUFeatures : public AllStatic { |
276 public: | 293 public: |
277 static void InitOnce(); | 294 static void InitOnce(); |
278 // x64 always has at least SSE2. | 295 // x64 always has at least SSE2. |
279 static bool sse2_supported() { return true; } | 296 static bool sse2_supported() { return true; } |
280 static bool sse4_1_supported(); | 297 static bool sse4_1_supported(); |
| 298 static bool double_truncate_round_supported() { return sse4_1_supported(); } |
281 | 299 |
282 private: | 300 private: |
283 static const uint64_t kSSE4_1BitMask = static_cast<uint64_t>(1) << 51; | 301 static const uint64_t kSSE4_1BitMask = static_cast<uint64_t>(1) << 51; |
284 | 302 |
285 static bool sse4_1_supported_; | 303 static bool sse4_1_supported_; |
286 #ifdef DEBUG | 304 #ifdef DEBUG |
287 static bool initialized_; | 305 static bool initialized_; |
288 #endif | 306 #endif |
289 }; | 307 }; |
290 | 308 |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 // Debugging and bringup support. | 667 // Debugging and bringup support. |
650 void Stop(const char* message); | 668 void Stop(const char* message); |
651 void Unimplemented(const char* message); | 669 void Unimplemented(const char* message); |
652 void Untested(const char* message); | 670 void Untested(const char* message); |
653 void Unreachable(const char* message); | 671 void Unreachable(const char* message); |
654 | 672 |
655 static void InitializeMemoryWithBreakpoints(uword data, int length); | 673 static void InitializeMemoryWithBreakpoints(uword data, int length); |
656 | 674 |
657 static const char* RegisterName(Register reg); | 675 static const char* RegisterName(Register reg); |
658 | 676 |
659 static const char* XmmRegisterName(XmmRegister reg); | 677 static const char* FpuRegisterName(FpuRegister reg); |
660 | 678 |
661 private: | 679 private: |
662 AssemblerBuffer buffer_; | 680 AssemblerBuffer buffer_; |
663 int prologue_offset_; | 681 int prologue_offset_; |
664 | 682 |
665 class CodeComment : public ZoneAllocated { | 683 class CodeComment : public ZoneAllocated { |
666 public: | 684 public: |
667 CodeComment(intptr_t pc_offset, const String& comment) | 685 CodeComment(intptr_t pc_offset, const String& comment) |
668 : pc_offset_(pc_offset), comment_(comment) { } | 686 : pc_offset_(pc_offset), comment_(comment) { } |
669 | 687 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 } | 807 } |
790 | 808 |
791 | 809 |
792 inline void Assembler::EmitOperandSizeOverride() { | 810 inline void Assembler::EmitOperandSizeOverride() { |
793 EmitUint8(0x66); | 811 EmitUint8(0x66); |
794 } | 812 } |
795 | 813 |
796 } // namespace dart | 814 } // namespace dart |
797 | 815 |
798 #endif // VM_ASSEMBLER_X64_H_ | 816 #endif // VM_ASSEMBLER_X64_H_ |
OLD | NEW |