trunc: Wasm SIMD conversion instruction
The trunc SIMD conversion instruction rounds the value in each lane of a v128 value interpretation to the nearest integer towards zero with a magnitude not larger than the input.
Try it
(module
(import "console" "log" (func $log (param f32)))
(func $main
v128.const f32x4 0.5 4.9 34.3 33.5
f32x4.trunc
f32x4.extract_lane 3
call $log ;; log the result
)
(start $main)
)
WebAssembly.instantiateStreaming(fetch("{%wasm-url%}"), { console });
Syntax
value_type.trunc
value_type-
The type of value the instruction is being run on. The following
v128value interpretations supporttrunc:f32x4f64x2
trunc-
The
truncinstruction. Must always be included after thevalue_typeand a period (.).
Type
[input] -> [output]
Binary encoding
| Instruction | Binary format | Example text => binary |
|---|---|---|
f32x4.trunc |
0xfd 105:u32 |
f32x4.trunc => 0xfd 0x69 |
f64x2.trunc |
0xfd 122:u32 |
f64x2.trunc => 0xfd 0x7a |