Wado

core:simd

Type-safe wrappers over the WebAssembly 128-bit SIMD instruction set. All types are newtypes of the primitive v128 and can be freely reinterpreted via as cast.

Types

Category Types
Signed integer i8x16, i16x8, i32x4, i64x2
Unsigned integer u8x16, u16x8, u32x4, u64x2
Floating-point f32x4, f64x2

Construction

Lane Access

Byte Selection

swizzle(indices) picks each byte of one vector by a runtime index, zeroing an index of 16 or more. To pick from two vectors, or to pick at no runtime cost, use builtin::i8x16_shuffle(l0, ..., l15, a, b): 0..=15 names a byte of a and 16..=31 a byte of b. Its sixteen indices are Wasm immediates, so they must be written as literals at the call — a method could not carry them until const generic parameters land.

Operators

All types support +, -, *, &, |, ^, ~, <<, >>, and unary -. Floating-point types additionally support /. Integer types do not support /.

Comparison Methods

All types provide eq, ne, lt, gt, le, ge. These return a mask vector (all-1s or all-0s per lane), not bool. Floating-point comparisons return the corresponding integer mask type (f32x4 -> i32x4).

Signed Integer Types (i8x16, i16x8, i32x4, i64x2)

Common methods: abs, all_true, bitmask, bitselect.

i8x16 specific: swizzle, add_sat_s/u, sub_sat_s/u, min_s/u, max_s/u, avgr_u, narrow_i16x8_s/u, popcnt, any_true, andnot.

i16x8 specific: add_sat_s/u, sub_sat_s/u, min_s/u, max_s/u, avgr_u, narrow_i32x4_s/u, extend_low/high_i8x16_s/u, extmul_low/high_i8x16_s/u, extadd_pairwise_i8x16_s/u, q15mulr_sat_s.

i32x4 specific: min_s/u, max_s/u, dot_i16x8_s, extend_low/high_i16x8_s/u, extmul_low/high_i16x8_s/u, extadd_pairwise_i16x8_s/u, trunc_sat_f32x4_s/u, trunc_sat_f64x2_s/u_zero.

i64x2 specific: extend_low/high_i32x4_s/u, extmul_low/high_i32x4_s/u.

Unsigned Integer Types (u8x16, u16x8, u32x4, u64x2)

u8x16: swizzle, relaxed_swizzle, abs, add_sat, sub_sat, min, max, avgr, all_true, bitmask, popcnt, bitselect.

u16x8: abs, add_sat, sub_sat, min, max, avgr, all_true, bitmask, bitselect.

u32x4: min, max, all_true, bitmask, bitselect.

u64x2: all_true, bitmask, bitselect.

Floating-Point Types (f32x4, f64x2)

sqrt, abs, min, max, ceil, floor, trunc, nearest, pmin, pmax, bitselect.

f32x4 specific: convert_i32x4_s/u, demote_f64x2_zero.

f64x2 specific: convert_low_i32x4_s/u, promote_low_f32x4.

Relaxed SIMD

Relaxed SIMD operations trade strict determinism for performance. Edge-case behavior (NaN, out-of-range) is host-defined, and fixed on one host. Methods use the relaxed_ prefix.

Synopsis

let a: i32x4 = [10, 2, 30, 4];
let b: i32x4 = [1, 20, 3, 40];
let mins = a.min_s(&b);
assert mins.extract_lane(0) == 1;
assert mins.extract_lane(3) == 4;

Types

pub type i8x16 = v128

pub type i16x8 = v128

pub type i32x4 = v128

pub type i64x2 = v128

pub type u8x16 = v128

pub type u16x8 = v128

pub type u32x4 = v128

pub type u64x2 = v128

pub type f32x4 = v128

pub type f64x2 = v128