Chromium Code Reviews| Index: src/compiler/machine-type.h |
| diff --git a/src/compiler/machine-type.h b/src/compiler/machine-type.h |
| index 716ca2236d958b4efabe2866ae5e6716573390a3..23ae73b0a45e686a563954462bb125e6d87c74a4 100644 |
| --- a/src/compiler/machine-type.h |
| +++ b/src/compiler/machine-type.h |
| @@ -5,30 +5,110 @@ |
| #ifndef V8_COMPILER_MACHINE_TYPE_H_ |
| #define V8_COMPILER_MACHINE_TYPE_H_ |
| +#include "src/ostreams.h" |
| +#include "src/v8.h" |
| + |
| namespace v8 { |
| namespace internal { |
| namespace compiler { |
| -// An enumeration of the storage representations at the machine level. |
| -// - Words are uninterpreted bits of a given fixed size that can be used |
| -// to store integers and pointers. They are normally allocated to general |
| -// purpose registers by the backend and are not tracked for GC. |
| -// - Floats are bits of a given fixed size that are used to store floating |
| -// point numbers. They are normally allocated to the floating point |
| -// registers of the machine and are not tracked for the GC. |
| -// - Tagged values are the size of a reference into the heap and can store |
| -// small words or references into the heap using a language and potentially |
| -// machine-dependent tagging scheme. These values are tracked by the code |
| -// generator for precise GC. |
| +// Machine-level types and representations. |
| +// TODO(titzer): Use the real type system instead of MachineType. |
| enum MachineType { |
| - kMachineWord8, |
| - kMachineWord16, |
| - kMachineWord32, |
| - kMachineWord64, |
| - kMachineFloat64, |
| - kMachineTagged, |
| - kMachineLast |
| + // Representations. |
| + rBit = 1 << 0, |
| + rWord8 = 1 << 1, |
| + rWord16 = 1 << 2, |
| + rWord32 = 1 << 3, |
| + rWord64 = 1 << 4, |
| + rFloat64 = 1 << 5, |
| + rTagged = 1 << 6, |
| + |
| + // Types. |
| + tBool = 1 << 7, |
| + tInt32 = 1 << 8, |
| + tUint32 = 1 << 9, |
| + tInt64 = 1 << 10, |
| + tUint64 = 1 << 11, |
| + tNumber = 1 << 12, |
| + tAny = 1 << 13 |
| }; |
| + |
| +typedef uint16_t MachineTypeUnion; |
| + |
| +#define PRINT(bit) \ |
| + if (type & bit) { \ |
| + if (before) os << "|"; \ |
| + os << #bit; \ |
| + before = true; \ |
| + } |
| + |
| +// Print a machine type or machine type union to a stream. |
| +inline void PrintMachineTypeUnionTo(OStream& os, MachineTypeUnion type) { |
| + bool before = false; |
| + PRINT(rBit); |
| + PRINT(rWord8); |
| + PRINT(rWord16); |
| + PRINT(rWord32); |
| + PRINT(rWord64); |
| + PRINT(rFloat64); |
| + PRINT(rTagged); |
| + |
| + PRINT(tBool); |
| + PRINT(tInt32); |
| + PRINT(tUint32); |
| + PRINT(tInt64); |
| + PRINT(tUint64); |
| + PRINT(tNumber); |
| + PRINT(tAny); |
| +} |
| + |
| +// Globally useful machine types and constants. |
| +const MachineTypeUnion rMask = |
| + rBit | rWord8 | rWord16 | rWord32 | rWord64 | rFloat64 | rTagged; |
| +const MachineTypeUnion tMask = |
| + tBool | tInt32 | tUint32 | tInt64 | tUint64 | tNumber | tAny; |
| + |
| +const MachineType mNone = static_cast<MachineType>(0); |
| +const MachineType mFloat64 = static_cast<MachineType>(rFloat64 | tNumber); |
| +const MachineType mInt8 = static_cast<MachineType>(rWord8 | tInt32); |
| +const MachineType mUint8 = static_cast<MachineType>(rWord8 | tUint32); |
| +const MachineType mInt16 = static_cast<MachineType>(rWord16 | tInt32); |
| +const MachineType mUint16 = static_cast<MachineType>(rWord16 | tUint32); |
| +const MachineType mInt32 = static_cast<MachineType>(rWord32 | tInt32); |
| +const MachineType mUint32 = static_cast<MachineType>(rWord32 | tUint32); |
| +const MachineType mInt64 = static_cast<MachineType>(rWord64 | tInt64); |
| +const MachineType mUint64 = static_cast<MachineType>(rWord64 | tUint64); |
| +const MachineType mPtr = kPointerSize == 4 ? rWord32 : rWord64; |
| +const MachineType mAnyTagged = static_cast<MachineType>(rTagged | tAny); |
| + |
| +// Gets only the representation of the given type. |
| +inline MachineType RepresentationOf(MachineType machine_type) { |
| + int result = machine_type & rMask; |
| + CHECK(IsPowerOf2(result)); |
| + return static_cast<MachineType>(result); |
| +} |
| + |
| +// Gets the element size of the machine type. |
|
Michael Starzinger
2014/08/13 15:40:05
nit: [...] size in bytes of [...]
titzer
2014/08/13 16:12:59
Done.
|
| +inline int ElementSizeOf(MachineType machine_type) { |
| + switch (RepresentationOf(machine_type)) { |
| + case rBit: |
| + case rWord8: |
| + return 1; |
| + case rWord16: |
| + return 2; |
| + case rWord32: |
| + return 4; |
| + case rWord64: |
| + case rFloat64: |
| + return 8; |
| + case rTagged: |
| + return kPointerSize; |
| + default: |
| + UNREACHABLE(); |
| + return kPointerSize; |
| + } |
| +} |
| } |
| } |
| } // namespace v8::internal::compiler |