MDN self-hosted library · e01.org

add_sat_u: Wasm SIMD arithmetic instruction

The addsatu SIMD arithmetic instruction performs a saturating addition of two unsigned v128 value interpretations — clamping the output to the range allowed by the value type. Each lane of the output value is the result of adding the corresponding lanes of the input value.

no runnable cells webassembly-instruction upstream source

The add_sat_u SIMD arithmetic instruction performs a saturating addition of two unsigned v128 value interpretations — clamping the output to the range allowed by the value type. Each lane of the output value is the result of adding the corresponding lanes of the input value.

tabbed-taller

```wat interactive-example (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.add_sat_u
i16x8.extract_lane_s 7
call $log ;; log the result

) (start $main) )


```js interactive-example
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.add_sat_u: 0 to 255 (the full range of an unsigned 8-bit integer)
  • i16x8.add_sat_u: 0 to 65,535 (the full range of an unsigned 16-bit integer)

Syntax

value_type.add_sat_u
  • value_type
  • : The type of value the instruction is being run on. The following types support add_sat_u:
    • i8x16
    • i16x8
  • add_sat_u
  • : The add_sat_u instruction. Must always be included after the value_type and a period (.).

Type

[input1, input2] -> [output]
  • input1
  • : The first input value.
  • input2
  • : The second input value.
  • output
  • : The output value.

Binary encoding

Instruction Binary format Example text => binary
i8x16.add_sat_u 0xfd 112:u32 i8x16.add_sat_u => 0xfd 0x70
i16x8.add_sat_u 0xfd 144:u32 i16x8.add_sat_u => 0xfd 0x90 0x01

Specifications

Browser compatibility

See also