5 #ifndef V8_WASM_WASM_VALUE_H_ 6 #define V8_WASM_WASM_VALUE_H_ 8 #include "src/boxed-float.h" 9 #include "src/v8memory.h" 10 #include "src/wasm/wasm-opcodes.h" 11 #include "src/zone/zone-containers.h" 17 #define FOREACH_SIMD_TYPE(V) \ 18 V(float, float4, f32x4, 4) \ 19 V(int32_t, int4, i32x4, 4) \ 20 V(int16_t, int8, i16x8, 8) \ 21 V(int8_t, int16, i8x16, 16) 23 #define DEFINE_SIMD_TYPE(cType, sType, name, kSize) \ 27 FOREACH_SIMD_TYPE(DEFINE_SIMD_TYPE)
28 #undef DEFINE_SIMD_TYPE 33 for (
size_t i = 0;
i < 16;
i++) {
37 #define DEFINE_SIMD_TYPE_SPECIFIC_METHODS(cType, sType, name, size) \ 38 explicit Simd128(sType val) { \ 39 WriteUnalignedValue<sType>(reinterpret_cast<Address>(val_), val); \ 42 return ReadUnalignedValue<sType>(reinterpret_cast<Address>(val_)); \ 44 FOREACH_SIMD_TYPE(DEFINE_SIMD_TYPE_SPECIFIC_METHODS)
45 #undef DEFINE_SIMD_TYPE_SPECIFIC_METHODS 56 #define FOREACH_WASMVAL_TYPE(V) \ 57 V(i32, kWasmI32, int32_t) \ 58 V(u32, kWasmI32, uint32_t) \ 59 V(i64, kWasmI64, int64_t) \ 60 V(u64, kWasmI64, uint64_t) \ 61 V(f32, kWasmF32, float) \ 62 V(f32_boxed, kWasmF32, Float32) \ 63 V(f64, kWasmF64, double) \ 64 V(f64_boxed, kWasmF64, Float64) \ 65 V(s128, kWasmS128, Simd128) 70 WasmValue() : type_(kWasmStmt), bit_pattern_{} {}
72 #define DEFINE_TYPE_SPECIFIC_METHODS(name, localtype, ctype) \ 73 explicit WasmValue(ctype v) : type_(localtype), bit_pattern_{} { \ 74 static_assert(sizeof(ctype) <= sizeof(bit_pattern_), \ 75 "size too big for WasmValue"); \ 76 WriteUnalignedValue<ctype>(reinterpret_cast<Address>(bit_pattern_), v); \ 78 ctype to_##name() const { \ 79 DCHECK_EQ(localtype, type_); \ 80 return to_##name##_unchecked(); \ 82 ctype to_##name##_unchecked() const { \ 83 return ReadUnalignedValue<ctype>(reinterpret_cast<Address>(bit_pattern_)); \ 85 FOREACH_WASMVAL_TYPE(DEFINE_TYPE_SPECIFIC_METHODS)
86 #undef DEFINE_TYPE_SPECIFIC_METHODS 88 ValueType
type()
const {
return type_; }
91 bool operator==(
const WasmValue& other)
const {
92 return type_ == other.type_ &&
93 !memcmp(bit_pattern_, other.bit_pattern_, 16);
100 inline T to_unchecked()
const;
104 uint8_t bit_pattern_[16];
107 #define DECLARE_CAST(name, localtype, ctype, ...) \ 109 inline ctype WasmValue::to_unchecked() const { \ 110 return to_##name##_unchecked(); \ 113 inline ctype WasmValue::to() const { \ 114 return to_##name(); \ 116 FOREACH_WASMVAL_TYPE(DECLARE_CAST)
123 #endif // V8_WASM_WASM_VALUE_H_