github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/engine/wazevo/ssa/type.go (about) 1 package ssa 2 3 type Type byte 4 5 const ( 6 typeInvalid Type = iota 7 8 // TODO: add 8, 16 bit types when it's needed for optimizations. 9 10 // TypeI32 represents an integer type with 32 bits. 11 TypeI32 12 13 // TypeI64 represents an integer type with 64 bits. 14 TypeI64 15 16 // TypeF32 represents 32-bit floats in the IEEE 754. 17 TypeF32 18 19 // TypeF64 represents 64-bit floats in the IEEE 754. 20 TypeF64 21 22 // TypeV128 represents 128-bit SIMD vectors. 23 TypeV128 24 ) 25 26 // String implements fmt.Stringer. 27 func (t Type) String() (ret string) { 28 switch t { 29 case typeInvalid: 30 return "invalid" 31 case TypeI32: 32 return "i32" 33 case TypeI64: 34 return "i64" 35 case TypeF32: 36 return "f32" 37 case TypeF64: 38 return "f64" 39 case TypeV128: 40 return "v128" 41 default: 42 panic(int(t)) 43 } 44 } 45 46 // IsInt returns true if the type is an integer type. 47 func (t Type) IsInt() bool { 48 return t == TypeI32 || t == TypeI64 49 } 50 51 // IsFloat returns true if the type is a floating point type. 52 func (t Type) IsFloat() bool { 53 return t == TypeF32 || t == TypeF64 54 } 55 56 // Bits returns the number of bits required to represent the type. 57 func (t Type) Bits() byte { 58 switch t { 59 case TypeI32, TypeF32: 60 return 32 61 case TypeI64, TypeF64: 62 return 64 63 case TypeV128: 64 return 128 65 default: 66 panic(int(t)) 67 } 68 } 69 70 // Size returns the number of bytes required to represent the type. 71 func (t Type) Size() byte { 72 return t.Bits() / 8 73 } 74 75 func (t Type) invalid() bool { 76 return t == typeInvalid 77 } 78 79 // VecLane represents a lane in a SIMD vector. 80 type VecLane byte 81 82 const ( 83 VecLaneInvalid VecLane = 1 + iota 84 VecLaneI8x16 85 VecLaneI16x8 86 VecLaneI32x4 87 VecLaneI64x2 88 VecLaneF32x4 89 VecLaneF64x2 90 ) 91 92 // String implements fmt.Stringer. 93 func (vl VecLane) String() (ret string) { 94 switch vl { 95 case VecLaneInvalid: 96 return "invalid" 97 case VecLaneI8x16: 98 return "i8x16" 99 case VecLaneI16x8: 100 return "i16x8" 101 case VecLaneI32x4: 102 return "i32x4" 103 case VecLaneI64x2: 104 return "i64x2" 105 case VecLaneF32x4: 106 return "f32x4" 107 case VecLaneF64x2: 108 return "f64x2" 109 default: 110 panic(int(vl)) 111 } 112 }