sub_sat_s: Wasm SIMD arithmetic instruction
The sub_sat_s SIMD arithmetic instruction performs a saturating subtraction of two signed v128 value interpretations — clamping the output to the range allowed by the value type. Each lane of the output value is the result of subtracting the corresponding lane of the second input from the corresponding lane of the first input.
Try it
(module
(import "console" "log" (func $log (param i32)))
(func $main
v128.const i16x8 4 6 16 8 23 65 82 9
v128.const i16x8 0 25 2 30 2 34 45 80
i16x8.sub_sat_s
i16x8.extract_lane_s 7
call $log ;; log the result
)
(start $main)
)
WebAssembly.instantiateStreaming(fetch("{%wasm-url%}"), { console });
Saturation means that the output values are clamped to the upper and lower values allowed by the value interpretation instead of wrapping. Allowed output values are:
i8x16.sub_sat_s:−128to127(the full range of a signed 8-bit integer)i16x8.sub_sat_s:−32,768to32,767(the full range of a signed 16-bit integer)
Syntax
value_type.sub_sat_s
value_type-
The type of value the instruction is being run on. The following types support
sub_sat_s:i8x16i16x8
sub_sat_s-
The
sub_sat_sinstruction. Must always be included after thevalue_typeand a period (.).
Type
[input1, input2] -> [output]
Binary encoding
| Instruction | Binary format | Example text => binary |
|---|---|---|
i8x16.sub_sat_s |
0xfd 114:u32 |
i8x16.sub_sat_s => 0xfd 0x72 |
i16x8.sub_sat_s |
0xfd 146:u32 |
i16x8.sub_sat_s => 0xfd 0x92 0x01 |