swizzle: Wasm SIMD conversion instruction
The swizzle SIMD conversion instruction returns a new v128 value with its lane values selected from an input v128 value, determined by indices provided in a second input v128.
Try it
(module
(import "console" "log" (func $log (param i32)))
(func $main
v128.const i8x16 10 23 56 15 25 29 92 45 36 4 78 12 34 25 72 82
v128.const i8x16 0 2 5 7 3 5 9 2 4 6 1 7 0 3 5 1
i8x16.swizzle
i8x16.extract_lane_u 6
call $log ;; log the result
)
(start $main)
)
WebAssembly.instantiateStreaming(fetch("{%wasm-url%}"), { console });
In the above example, we extract and log the value at index position 6 of the swizzle instruction output value. This will be 4, because the swizzle instruction has selected the value at index position 9 of the input value to be put at index position 6 of the output value.
Syntax
value_type.swizzle
value_type-
The type of value the instruction is being run on. The following
v128value interpretations supportswizzle:i8x16
swizzle-
The
swizzleinstruction. Must always be included after thevalue_typeand a period (.).
Type
[input, indices] -> [output]
input-
The input
v128i8x16value interpretation. indices-
The
v128value containing the indices you want to use to select which values should be taken from the input value and included in the output. In each case, the index number represents the index position to take from the input value, and the position of the index represents the position it should appear in theoutputvalue.These values must be between
0and15, inclusive. For indices outside this range, the resulting lanes will be initialized to0. output-
The output
v128value interpretation.
Binary encoding
| Instruction | Binary format | Example text => binary |
|---|---|---|
i8x16.swizzle |
0xfd 14:u32 |
i8x16.swizzle => 0xfd 0x0e |