5 #ifndef V8_WASM_VALUE_TYPE_H_ 6 #define V8_WASM_VALUE_TYPE_H_ 8 #include "src/machine-type.h" 9 #include "src/wasm/wasm-constants.h" 19 enum ValueType : uint8_t {
32 using FunctionSig = Signature<ValueType>;
34 inline size_t hash_value(ValueType type) {
return static_cast<size_t>(type); }
38 #define FOREACH_LOAD_TYPE(V) \ 41 V(I32, 8U, Uint8, 0) \ 42 V(I32, 16S, Int16, 1) \ 43 V(I32, 16U, Uint16, 1) \ 46 V(I64, 8U, Uint8, 0) \ 47 V(I64, 16S, Int16, 1) \ 48 V(I64, 16U, Uint16, 1) \ 49 V(I64, 32S, Int32, 2) \ 50 V(I64, 32U, Uint32, 2) \ 51 V(F32, , Float32, 2) \ 52 V(F64, , Float64, 3) \ 57 enum LoadTypeValue : uint8_t {
58 #define DEF_ENUM(type, suffix, ...) k##type##Load##suffix, 59 FOREACH_LOAD_TYPE(DEF_ENUM)
64 constexpr
LoadType(LoadTypeValue val)
67 constexpr LoadTypeValue value()
const {
return val_; }
68 constexpr
unsigned size_log_2()
const {
return kLoadSizeLog2[val_]; }
69 constexpr
unsigned size()
const {
return 1 << size_log_2(); }
70 constexpr ValueType value_type()
const {
return kValueType[val_]; }
71 constexpr
MachineType mem_type()
const {
return kMemType[val_]; }
89 const LoadTypeValue val_;
91 static constexpr uint8_t kLoadSizeLog2[] = {
92 #define LOAD_SIZE(_, __, ___, size) size, 93 FOREACH_LOAD_TYPE(LOAD_SIZE)
97 static constexpr ValueType kValueType[] = {
98 #define VALUE_TYPE(type, ...) kWasm##type, 99 FOREACH_LOAD_TYPE(VALUE_TYPE)
104 #define MEMTYPE(_, __, memtype, ___) MachineType::memtype(), 105 FOREACH_LOAD_TYPE(MEMTYPE)
110 #define FOREACH_STORE_TYPE(V) \ 111 V(I32, , Word32, 2) \ 112 V(I32, 8, Word8, 0) \ 113 V(I32, 16, Word16, 1) \ 114 V(I64, , Word64, 3) \ 115 V(I64, 8, Word8, 0) \ 116 V(I64, 16, Word16, 1) \ 117 V(I64, 32, Word32, 2) \ 118 V(F32, , Float32, 2) \ 119 V(F64, , Float64, 3) \ 120 V(S128, , Simd128, 4) 124 enum StoreTypeValue : uint8_t {
125 #define DEF_ENUM(type, suffix, ...) k##type##Store##suffix, 126 FOREACH_STORE_TYPE(DEF_ENUM)
134 constexpr StoreTypeValue value()
const {
return val_; }
135 constexpr
unsigned size_log_2()
const {
return kStoreSizeLog2[val_]; }
136 constexpr
unsigned size()
const {
return 1 << size_log_2(); }
137 constexpr ValueType value_type()
const {
return kValueType[val_]; }
138 constexpr MachineRepresentation mem_rep()
const {
return kMemRep[val_]; }
156 const StoreTypeValue val_;
158 static constexpr uint8_t kStoreSizeLog2[] = {
159 #define STORE_SIZE(_, __, ___, size) size, 160 FOREACH_STORE_TYPE(STORE_SIZE)
164 static constexpr ValueType kValueType[] = {
165 #define VALUE_TYPE(type, ...) kWasm##type, 166 FOREACH_STORE_TYPE(VALUE_TYPE)
170 static constexpr MachineRepresentation kMemRep[] = {
171 #define MEMREP(_, __, memrep, ___) MachineRepresentation::k##memrep, 172 FOREACH_STORE_TYPE(MEMREP)
181 return 1 << i::ElementSizeLog2Of(
type.representation());
184 static int ElementSizeInBytes(ValueType
type) {
199 static int ElementSizeLog2Of(ValueType
type) {
214 static byte MemSize(ValueType
type) {
return 1 << ElementSizeLog2Of(
type); }
216 static ValueTypeCode ValueTypeCodeFor(ValueType
type) {
231 return kLocalExceptRef;
242 return MachineType::Int32();
244 return MachineType::Int64();
246 return MachineType::Float32();
248 return MachineType::Float64();
251 return MachineType::TaggedPointer();
253 return MachineType::Simd128();
255 return MachineType::None();
261 static MachineRepresentation MachineRepresentationFor(ValueType
type) {
264 return MachineRepresentation::kWord32;
266 return MachineRepresentation::kWord64;
268 return MachineRepresentation::kFloat32;
270 return MachineRepresentation::kFloat64;
272 return MachineRepresentation::kTaggedPointer;
274 return MachineRepresentation::kSimd128;
276 return MachineRepresentation::kNone;
283 switch (
type.representation()) {
284 case MachineRepresentation::kWord8:
285 case MachineRepresentation::kWord16:
286 case MachineRepresentation::kWord32:
288 case MachineRepresentation::kWord64:
290 case MachineRepresentation::kFloat32:
292 case MachineRepresentation::kFloat64:
294 case MachineRepresentation::kTaggedPointer:
296 case MachineRepresentation::kSimd128:
303 static char ShortNameOf(ValueType
type) {
326 static const char* TypeName(ValueType
type) {
357 #endif // V8_WASM_VALUE_TYPE_H_