5 #ifndef V8_MACHINE_TYPE_H_ 6 #define V8_MACHINE_TYPE_H_ 10 #include "src/base/bits.h" 11 #include "src/globals.h" 16 enum class MachineRepresentation : uint8_t {
30 kFirstFPRepresentation = kFloat32,
31 kLastRepresentation = kSimd128
34 bool IsSubtype(MachineRepresentation rep1, MachineRepresentation rep2);
36 static_assert(static_cast<int>(MachineRepresentation::kLastRepresentation) <
37 kIntSize * kBitsPerByte,
38 "Bit masks of MachineRepresentation should fit in an int");
40 V8_EXPORT_PRIVATE
const char* MachineReprToString(MachineRepresentation);
42 enum class MachineSemantic : uint8_t {
53 V8_EXPORT_PRIVATE
inline int ElementSizeLog2Of(MachineRepresentation rep);
55 V8_EXPORT_PRIVATE
inline int ElementSizeInBytes(MachineRepresentation rep);
60 : representation_(MachineRepresentation::kNone),
61 semantic_(MachineSemantic::kNone) {}
62 constexpr
MachineType(MachineRepresentation representation,
63 MachineSemantic semantic)
64 : representation_(representation), semantic_(semantic) {}
66 constexpr
bool operator==(
MachineType other)
const {
67 return representation() == other.representation() &&
68 semantic() == other.semantic();
71 constexpr
bool operator!=(
MachineType other)
const {
72 return !(*
this == other);
75 constexpr MachineRepresentation representation()
const {
76 return representation_;
78 constexpr MachineSemantic semantic()
const {
return semantic_; }
80 constexpr
bool IsNone()
const {
81 return representation() == MachineRepresentation::kNone;
84 constexpr
bool IsSigned()
const {
85 return semantic() == MachineSemantic::kInt32 ||
86 semantic() == MachineSemantic::kInt64;
88 constexpr
bool IsUnsigned()
const {
89 return semantic() == MachineSemantic::kUint32 ||
90 semantic() == MachineSemantic::kUint64;
92 constexpr
bool IsTagged()
const {
93 return representation() == MachineRepresentation::kTaggedPointer ||
94 representation() == MachineRepresentation::kTaggedSigned ||
95 representation() == MachineRepresentation::kTagged;
97 constexpr
bool IsTaggedSigned()
const {
98 return representation() == MachineRepresentation::kTaggedSigned;
100 constexpr
bool IsTaggedPointer()
const {
101 return representation() == MachineRepresentation::kTaggedPointer;
103 constexpr
static MachineRepresentation PointerRepresentation() {
104 return (kPointerSize == 4) ? MachineRepresentation::kWord32
105 : MachineRepresentation::kWord64;
108 return (kPointerSize == 4) ?
Uint32() : Uint64();
111 return (kPointerSize == 4) ?
Int32() : Int64();
114 return MachineType(MachineRepresentation::kWord8, MachineSemantic::kInt32);
117 return MachineType(MachineRepresentation::kWord8, MachineSemantic::kUint32);
120 return MachineType(MachineRepresentation::kWord16, MachineSemantic::kInt32);
124 MachineSemantic::kUint32);
127 return MachineType(MachineRepresentation::kWord32, MachineSemantic::kInt32);
131 MachineSemantic::kUint32);
134 return MachineType(MachineRepresentation::kWord64, MachineSemantic::kInt64);
138 MachineSemantic::kUint64);
141 return MachineType(MachineRepresentation::kFloat32,
142 MachineSemantic::kNumber);
145 return MachineType(MachineRepresentation::kFloat64,
146 MachineSemantic::kNumber);
149 return MachineType(MachineRepresentation::kSimd128, MachineSemantic::kNone);
152 return MachineType(PointerRepresentation(), MachineSemantic::kNone);
155 return MachineType(MachineRepresentation::kTaggedPointer,
156 MachineSemantic::kAny);
159 return MachineType(MachineRepresentation::kTaggedSigned,
160 MachineSemantic::kInt32);
163 return MachineType(MachineRepresentation::kTagged, MachineSemantic::kAny);
166 return MachineType(MachineRepresentation::kBit, MachineSemantic::kBool);
169 return MachineType(MachineRepresentation::kTagged, MachineSemantic::kBool);
172 return MachineType(MachineRepresentation::kNone, MachineSemantic::kNone);
177 return MachineType(MachineRepresentation::kWord8, MachineSemantic::kNone);
180 return MachineType(MachineRepresentation::kWord16, MachineSemantic::kNone);
183 return MachineType(MachineRepresentation::kWord32, MachineSemantic::kNone);
186 return MachineType(MachineRepresentation::kWord64, MachineSemantic::kNone);
189 return MachineType(MachineRepresentation::kFloat32, MachineSemantic::kNone);
192 return MachineType(MachineRepresentation::kFloat64, MachineSemantic::kNone);
195 return MachineType(MachineRepresentation::kSimd128, MachineSemantic::kNone);
198 return MachineType(MachineRepresentation::kTagged, MachineSemantic::kNone);
201 return MachineType(MachineRepresentation::kBit, MachineSemantic::kNone);
204 static MachineType TypeForRepresentation(
const MachineRepresentation& rep,
205 bool isSigned =
true) {
207 case MachineRepresentation::kNone:
208 return MachineType::None();
209 case MachineRepresentation::kBit:
210 return MachineType::Bool();
211 case MachineRepresentation::kWord8:
212 return isSigned ? MachineType::Int8() : MachineType::Uint8();
213 case MachineRepresentation::kWord16:
214 return isSigned ? MachineType::Int16() : MachineType::Uint16();
215 case MachineRepresentation::kWord32:
216 return isSigned ? MachineType::Int32() : MachineType::Uint32();
217 case MachineRepresentation::kWord64:
218 return isSigned ? MachineType::Int64() : MachineType::Uint64();
219 case MachineRepresentation::kFloat32:
220 return MachineType::Float32();
221 case MachineRepresentation::kFloat64:
222 return MachineType::Float64();
223 case MachineRepresentation::kSimd128:
224 return MachineType::Simd128();
225 case MachineRepresentation::kTagged:
226 return MachineType::AnyTagged();
227 case MachineRepresentation::kTaggedSigned:
228 return MachineType::TaggedSigned();
229 case MachineRepresentation::kTaggedPointer:
230 return MachineType::TaggedPointer();
236 bool LessThanOrEqualPointerSize() {
237 return ElementSizeLog2Of(this->representation()) <= kPointerSizeLog2;
241 MachineRepresentation representation_;
242 MachineSemantic semantic_;
245 V8_INLINE
size_t hash_value(MachineRepresentation rep) {
246 return static_cast<size_t>(rep);
249 V8_INLINE
size_t hash_value(MachineType
type) {
250 return static_cast<size_t>(
type.representation()) +
251 static_cast<size_t>(
type.semantic()) * 16;
254 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
255 MachineRepresentation rep);
256 std::ostream& operator<<(std::ostream& os, MachineSemantic type);
257 V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, MachineType type);
259 inline bool IsFloatingPoint(MachineRepresentation rep) {
260 return rep >= MachineRepresentation::kFirstFPRepresentation;
263 inline bool CanBeTaggedPointer(MachineRepresentation rep) {
264 return rep == MachineRepresentation::kTagged ||
265 rep == MachineRepresentation::kTaggedPointer;
268 inline bool CanBeTaggedSigned(MachineRepresentation rep) {
269 return rep == MachineRepresentation::kTagged ||
270 rep == MachineRepresentation::kTaggedSigned;
273 inline bool IsAnyTagged(MachineRepresentation rep) {
274 return CanBeTaggedPointer(rep) || rep == MachineRepresentation::kTaggedSigned;
278 V8_EXPORT_PRIVATE
inline int ElementSizeLog2Of(MachineRepresentation rep) {
280 case MachineRepresentation::kBit:
281 case MachineRepresentation::kWord8:
283 case MachineRepresentation::kWord16:
285 case MachineRepresentation::kWord32:
286 case MachineRepresentation::kFloat32:
288 case MachineRepresentation::kWord64:
289 case MachineRepresentation::kFloat64:
291 case MachineRepresentation::kSimd128:
293 case MachineRepresentation::kTaggedSigned:
294 case MachineRepresentation::kTaggedPointer:
295 case MachineRepresentation::kTagged:
296 return kPointerSizeLog2;
303 V8_EXPORT_PRIVATE
inline int ElementSizeInBytes(MachineRepresentation rep) {
304 return 1 << ElementSizeLog2Of(rep);
308 V8_EXPORT_PRIVATE
inline constexpr
int RepresentationBit(
309 MachineRepresentation rep) {
310 return 1 <<
static_cast<int>(rep);
316 #endif // V8_MACHINE_TYPE_H_