MDN / splat: Wasm SIMD conversion instruction
MDN / splat: Wasm SIMD conversion instruction
The splat SIMD conversion instruction copies the same value to all lanes of a v128 value interpretation.
(module
(import "console" "log" (func $log (param f32)))
(func $main
(local $s v128)
f32.const 16.2
f32x4.splat
local.set $s
local.get $s
f32x4.extract_lane 0
call $log ;; log the result
local.get $s
f32x4.extract_lane 1
call $log ;; log the result
local.get $s
f32x4.extract_lane 2
call $log ;; log the result
local.get $s
f32x4.extract_lane 3
call $log ;; log the result
)
(start $main)
)
WebAssembly.instantiateStreaming(fetch("{%wasm-url%}"), { console });
Syntax
value_type.splat
value_type: The type of value the instruction is being run on. The following
v128value interpretations supportsplat:i8x16i16x8i32x4i64x2f32x4f64x2
splat: The
splatinstruction. Must always be included after thevalue_typeand a period (.).
Type
[input, value] -> [output]
input: The input
v128value interpretation.
value: The value you want to copy to all lanes of the
v128.
output: The resulting
v128value interpretation after all lanes of the input value have been set to thevalue.
Binary encoding
InstructionBinary formatExample text => binaryi8x16.splat0xfd 15:u32i8x16.splat => 0xfd 0x0fi16x8.splat0xfd 16:u32i16x8.splat => 0xfd 0x10i32x4.splat0xfd 17:u32i32x4.splat => 0xfd 0x11i64x2.splat0xfd 18:u32i64x2.splat => 0xfd 0x12f32x4.splat0xfd 19:u32f32x4.splat => 0xfd 0x13f64x2.splat0xfd 20:u32f64x2.splat => 0xfd 0x14