OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_COMPILER_MACHINE_TYPE_H_ | 5 #ifndef V8_COMPILER_MACHINE_TYPE_H_ |
6 #define V8_COMPILER_MACHINE_TYPE_H_ | 6 #define V8_COMPILER_MACHINE_TYPE_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 | 9 |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 return static_cast<MachineType>(result); | 74 return static_cast<MachineType>(result); |
75 } | 75 } |
76 | 76 |
77 // Gets only the representation of the given type. | 77 // Gets only the representation of the given type. |
78 inline MachineType RepresentationOf(MachineType machine_type) { | 78 inline MachineType RepresentationOf(MachineType machine_type) { |
79 int result = machine_type & kRepMask; | 79 int result = machine_type & kRepMask; |
80 CHECK(base::bits::IsPowerOfTwo32(result)); | 80 CHECK(base::bits::IsPowerOfTwo32(result)); |
81 return static_cast<MachineType>(result); | 81 return static_cast<MachineType>(result); |
82 } | 82 } |
83 | 83 |
| 84 // Gets the log2 of the element size in bytes of the machine type. |
| 85 inline int ElementSizeLog2Of(MachineType machine_type) { |
| 86 switch (RepresentationOf(machine_type)) { |
| 87 case kRepBit: |
| 88 case kRepWord8: |
| 89 return 0; |
| 90 case kRepWord16: |
| 91 return 1; |
| 92 case kRepWord32: |
| 93 case kRepFloat32: |
| 94 return 2; |
| 95 case kRepWord64: |
| 96 case kRepFloat64: |
| 97 return 3; |
| 98 case kRepTagged: |
| 99 return kPointerSizeLog2; |
| 100 default: |
| 101 break; |
| 102 } |
| 103 UNREACHABLE(); |
| 104 return -1; |
| 105 } |
| 106 |
84 // Gets the element size in bytes of the machine type. | 107 // Gets the element size in bytes of the machine type. |
85 inline int ElementSizeOf(MachineType machine_type) { | 108 inline int ElementSizeOf(MachineType machine_type) { |
86 switch (RepresentationOf(machine_type)) { | 109 const int shift = ElementSizeLog2Of(machine_type); |
87 case kRepBit: | 110 DCHECK_NE(-1, shift); |
88 case kRepWord8: | 111 return 1 << shift; |
89 return 1; | |
90 case kRepWord16: | |
91 return 2; | |
92 case kRepWord32: | |
93 case kRepFloat32: | |
94 return 4; | |
95 case kRepWord64: | |
96 case kRepFloat64: | |
97 return 8; | |
98 case kRepTagged: | |
99 return kPointerSize; | |
100 default: | |
101 UNREACHABLE(); | |
102 return kPointerSize; | |
103 } | |
104 } | 112 } |
105 | 113 |
106 // Describes the inputs and outputs of a function or call. | 114 // Describes the inputs and outputs of a function or call. |
107 template <typename T> | 115 template <typename T> |
108 class Signature : public ZoneObject { | 116 class Signature : public ZoneObject { |
109 public: | 117 public: |
110 Signature(size_t return_count, size_t parameter_count, T* reps) | 118 Signature(size_t return_count, size_t parameter_count, T* reps) |
111 : return_count_(return_count), | 119 : return_count_(return_count), |
112 parameter_count_(parameter_count), | 120 parameter_count_(parameter_count), |
113 reps_(reps) {} | 121 reps_(reps) {} |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 size_t parameter_count_; | 174 size_t parameter_count_; |
167 T* reps_; | 175 T* reps_; |
168 }; | 176 }; |
169 | 177 |
170 typedef Signature<MachineType> MachineSignature; | 178 typedef Signature<MachineType> MachineSignature; |
171 } // namespace compiler | 179 } // namespace compiler |
172 } // namespace internal | 180 } // namespace internal |
173 } // namespace v8 | 181 } // namespace v8 |
174 | 182 |
175 #endif // V8_COMPILER_MACHINE_TYPE_H_ | 183 #endif // V8_COMPILER_MACHINE_TYPE_H_ |
OLD | NEW |