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
T::splat(value)— broadcast a scalar to all lanes- Tuple literal coercion —
let v: i32x4 = [1, 2, 3, 4]; - Bitwise reinterpret —
let u = signed as u32x4;
Lane Access
extract_lane(index)— returns the lane value (i32/i64/f32/f64 depending on type)extract_lane_s(index)/extract_lane_u(index)— sign/zero-extended extraction for sub-32-bit types (i8x16, i16x8)
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.
- FMA:
f32x4/f64x2.relaxed_madd(b, c)(a_b+c),relaxed_nmadd(b, c)(-(a_b)+c) - Min/Max:
f32x4/f64x2.relaxed_min/max(faster, NaN behavior varies) - Truncation:
i32x4::relaxed_trunc_f32x4_s/u,relaxed_trunc_f64x2_s/u_zero - Lane select:
i8x16/i16x8/i32x4/i64x2.relaxed_laneselect - Swizzle:
i8x16.relaxed_swizzle(out-of-range indices host-defined) - Q15 multiply:
i16x8.relaxed_q15mulr_s - Dot product:
i16x8.relaxed_dot_i8x16_i7x16_s,i32x4.relaxed_dot_i8x16_i7x16_add_s
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 fn splat(a: i32) -> i8x16
pub fn extract_lane_s(&self, lane: i32) -> i32
pub fn extract_lane_u(&self, lane: i32) -> i32
pub fn eq(&self, other: &i8x16) -> i8x16
pub fn ne(&self, other: &i8x16) -> i8x16
pub fn lt(&self, other: &i8x16) -> i8x16
pub fn gt(&self, other: &i8x16) -> i8x16
pub fn le(&self, other: &i8x16) -> i8x16
pub fn ge(&self, other: &i8x16) -> i8x16
pub fn swizzle(&self, indices: &i8x16) -> i8x16
pub fn abs(&self) -> i8x16
pub fn add_sat_s(&self, other: &i8x16) -> i8x16
pub fn add_sat_u(&self, other: &i8x16) -> i8x16
pub fn sub_sat_s(&self, other: &i8x16) -> i8x16
pub fn sub_sat_u(&self, other: &i8x16) -> i8x16
pub fn min_s(&self, other: &i8x16) -> i8x16
pub fn min_u(&self, other: &i8x16) -> i8x16
pub fn max_s(&self, other: &i8x16) -> i8x16
pub fn max_u(&self, other: &i8x16) -> i8x16
pub fn avgr_u(&self, other: &i8x16) -> i8x16
pub fn all_true(&self) -> bool
pub fn bitmask(&self) -> i32
pub fn narrow_i16x8_s(&self, other: &i8x16) -> i8x16
pub fn narrow_i16x8_u(&self, other: &i8x16) -> i8x16
pub fn popcnt(&self) -> i8x16
pub fn any_true(&self) -> bool
pub fn andnot(&self, other: &i8x16) -> i8x16
pub fn bitselect(&self, mask: &i8x16, other: &i8x16) -> i8x16
pub fn relaxed_swizzle(&self, indices: &i8x16) -> i8x16
pub fn relaxed_laneselect(&self, other: &i8x16, mask: &i8x16) -> i8x16
impl Add for i8x16
fn add(&self, rhs: &i8x16) -> i8x16
impl Sub for i8x16
fn sub(&self, rhs: &i8x16) -> i8x16
impl Neg for i8x16
fn neg(&self) -> i8x16
impl BitAnd for i8x16
fn bitand(&self, rhs: &i8x16) -> i8x16
impl BitOr for i8x16
fn bitor(&self, rhs: &i8x16) -> i8x16
impl BitXor for i8x16
fn bitxor(&self, rhs: &i8x16) -> i8x16
impl BitNot for i8x16
fn bitnot(&self) -> i8x16
impl Shl<u32> for i8x16
fn shl(&self, rhs: &u32) -> i8x16
impl Shr<u32> for i8x16
fn shr(&self, rhs: &u32) -> i8x16
impl From<Array<i32>> for i8x16
fn from(lanes: Array<i32>) -> i8x16
pub type i16x8 = v128
pub fn splat(a: i32) -> i16x8
pub fn extract_lane_s(&self, lane: i32) -> i32
pub fn extract_lane_u(&self, lane: i32) -> i32
pub fn eq(&self, other: &i16x8) -> i16x8
pub fn ne(&self, other: &i16x8) -> i16x8
pub fn lt(&self, other: &i16x8) -> i16x8
pub fn gt(&self, other: &i16x8) -> i16x8
pub fn le(&self, other: &i16x8) -> i16x8
pub fn ge(&self, other: &i16x8) -> i16x8
pub fn abs(&self) -> i16x8
pub fn add_sat_s(&self, other: &i16x8) -> i16x8
pub fn add_sat_u(&self, other: &i16x8) -> i16x8
pub fn sub_sat_s(&self, other: &i16x8) -> i16x8
pub fn sub_sat_u(&self, other: &i16x8) -> i16x8
pub fn min_s(&self, other: &i16x8) -> i16x8
pub fn min_u(&self, other: &i16x8) -> i16x8
pub fn max_s(&self, other: &i16x8) -> i16x8
pub fn max_u(&self, other: &i16x8) -> i16x8
pub fn avgr_u(&self, other: &i16x8) -> i16x8
pub fn all_true(&self) -> bool
pub fn bitmask(&self) -> i32
pub fn narrow_i32x4_s(&self, other: &i16x8) -> i16x8
pub fn narrow_i32x4_u(&self, other: &i16x8) -> i16x8
pub fn extend_low_i8x16_s(a: i8x16) -> i16x8
pub fn extend_high_i8x16_s(a: i8x16) -> i16x8
pub fn extend_low_i8x16_u(a: i8x16) -> i16x8
pub fn extend_high_i8x16_u(a: i8x16) -> i16x8
pub fn extmul_low_i8x16_s(&self, other: &i16x8) -> i16x8
pub fn extmul_high_i8x16_s(&self, other: &i16x8) -> i16x8
pub fn extmul_low_i8x16_u(&self, other: &i16x8) -> i16x8
pub fn extmul_high_i8x16_u(&self, other: &i16x8) -> i16x8
pub fn extadd_pairwise_i8x16_s(a: i8x16) -> i16x8
pub fn extadd_pairwise_i8x16_u(a: i8x16) -> i16x8
pub fn q15mulr_sat_s(&self, other: &i16x8) -> i16x8
pub fn bitselect(&self, mask: &i16x8, other: &i16x8) -> i16x8
pub fn relaxed_laneselect(&self, other: &i16x8, mask: &i16x8) -> i16x8
pub fn relaxed_q15mulr_s(&self, other: &i16x8) -> i16x8
pub fn relaxed_dot_i8x16_i7x16_s(&self, other: &i16x8) -> i16x8
impl Add for i16x8
fn add(&self, rhs: &i16x8) -> i16x8
impl Sub for i16x8
fn sub(&self, rhs: &i16x8) -> i16x8
impl Mul for i16x8
fn mul(&self, rhs: &i16x8) -> i16x8
impl Neg for i16x8
fn neg(&self) -> i16x8
impl BitAnd for i16x8
fn bitand(&self, rhs: &i16x8) -> i16x8
impl BitOr for i16x8
fn bitor(&self, rhs: &i16x8) -> i16x8
impl BitXor for i16x8
fn bitxor(&self, rhs: &i16x8) -> i16x8
impl BitNot for i16x8
fn bitnot(&self) -> i16x8
impl Shl<u32> for i16x8
fn shl(&self, rhs: &u32) -> i16x8
impl Shr<u32> for i16x8
fn shr(&self, rhs: &u32) -> i16x8
impl From<Array<i32>> for i16x8
fn from(lanes: Array<i32>) -> i16x8
pub type i32x4 = v128
pub fn splat(a: i32) -> i32x4
pub fn extract_lane(&self, lane: i32) -> i32
pub fn eq(&self, other: &i32x4) -> i32x4
pub fn ne(&self, other: &i32x4) -> i32x4
pub fn lt(&self, other: &i32x4) -> i32x4
pub fn gt(&self, other: &i32x4) -> i32x4
pub fn le(&self, other: &i32x4) -> i32x4
pub fn ge(&self, other: &i32x4) -> i32x4
pub fn abs(&self) -> i32x4
pub fn all_true(&self) -> bool
pub fn bitmask(&self) -> i32
pub fn min_s(&self, other: &i32x4) -> i32x4
pub fn min_u(&self, other: &i32x4) -> i32x4
pub fn max_s(&self, other: &i32x4) -> i32x4
pub fn max_u(&self, other: &i32x4) -> i32x4
pub fn dot_i16x8_s(&self, other: &i32x4) -> i32x4
pub fn extend_low_i16x8_s(a: i16x8) -> i32x4
pub fn extend_high_i16x8_s(a: i16x8) -> i32x4
pub fn extend_low_i16x8_u(a: i16x8) -> i32x4
pub fn extend_high_i16x8_u(a: i16x8) -> i32x4
pub fn extmul_low_i16x8_s(&self, other: &i32x4) -> i32x4
pub fn extmul_high_i16x8_s(&self, other: &i32x4) -> i32x4
pub fn extmul_low_i16x8_u(&self, other: &i32x4) -> i32x4
pub fn extmul_high_i16x8_u(&self, other: &i32x4) -> i32x4
pub fn extadd_pairwise_i16x8_s(a: i16x8) -> i32x4
pub fn extadd_pairwise_i16x8_u(a: i16x8) -> i32x4
pub fn trunc_sat_f32x4_s(a: f32x4) -> i32x4
pub fn trunc_sat_f32x4_u(a: f32x4) -> i32x4
pub fn trunc_sat_f64x2_s_zero(a: f64x2) -> i32x4
pub fn trunc_sat_f64x2_u_zero(a: f64x2) -> i32x4
pub fn bitselect(&self, mask: &i32x4, other: &i32x4) -> i32x4
pub fn relaxed_laneselect(&self, other: &i32x4, mask: &i32x4) -> i32x4
pub fn relaxed_trunc_f32x4_s(a: f32x4) -> i32x4
pub fn relaxed_trunc_f32x4_u(a: f32x4) -> i32x4
pub fn relaxed_trunc_f64x2_s_zero(a: f64x2) -> i32x4
pub fn relaxed_trunc_f64x2_u_zero(a: f64x2) -> i32x4
pub fn relaxed_dot_i8x16_i7x16_add_s(a: i8x16, b: i8x16, c: &i32x4) -> i32x4
impl Add for i32x4
fn add(&self, rhs: &i32x4) -> i32x4
impl Sub for i32x4
fn sub(&self, rhs: &i32x4) -> i32x4
impl Mul for i32x4
fn mul(&self, rhs: &i32x4) -> i32x4
impl Neg for i32x4
fn neg(&self) -> i32x4
impl BitAnd for i32x4
fn bitand(&self, rhs: &i32x4) -> i32x4
impl BitOr for i32x4
fn bitor(&self, rhs: &i32x4) -> i32x4
impl BitXor for i32x4
fn bitxor(&self, rhs: &i32x4) -> i32x4
impl BitNot for i32x4
fn bitnot(&self) -> i32x4
impl Shl<u32> for i32x4
fn shl(&self, rhs: &u32) -> i32x4
impl Shr<u32> for i32x4
fn shr(&self, rhs: &u32) -> i32x4
impl From<Array<i32>> for i32x4
fn from(lanes: Array<i32>) -> i32x4
pub type i64x2 = v128
pub fn splat(a: i64) -> i64x2
pub fn extract_lane(&self, lane: i32) -> i64
pub fn eq(&self, other: &i64x2) -> i64x2
pub fn ne(&self, other: &i64x2) -> i64x2
pub fn lt(&self, other: &i64x2) -> i64x2
pub fn gt(&self, other: &i64x2) -> i64x2
pub fn le(&self, other: &i64x2) -> i64x2
pub fn ge(&self, other: &i64x2) -> i64x2
pub fn abs(&self) -> i64x2
pub fn all_true(&self) -> bool
pub fn bitmask(&self) -> i32
pub fn extend_low_i32x4_s(a: i32x4) -> i64x2
pub fn extend_high_i32x4_s(a: i32x4) -> i64x2
pub fn extend_low_i32x4_u(a: i32x4) -> i64x2
pub fn extend_high_i32x4_u(a: i32x4) -> i64x2
pub fn extmul_low_i32x4_s(&self, other: &i64x2) -> i64x2
pub fn extmul_high_i32x4_s(&self, other: &i64x2) -> i64x2
pub fn extmul_low_i32x4_u(&self, other: &i64x2) -> i64x2
pub fn extmul_high_i32x4_u(&self, other: &i64x2) -> i64x2
pub fn bitselect(&self, mask: &i64x2, other: &i64x2) -> i64x2
pub fn relaxed_laneselect(&self, other: &i64x2, mask: &i64x2) -> i64x2
impl Add for i64x2
fn add(&self, rhs: &i64x2) -> i64x2
impl Sub for i64x2
fn sub(&self, rhs: &i64x2) -> i64x2
impl Mul for i64x2
fn mul(&self, rhs: &i64x2) -> i64x2
impl Neg for i64x2
fn neg(&self) -> i64x2
impl BitAnd for i64x2
fn bitand(&self, rhs: &i64x2) -> i64x2
impl BitOr for i64x2
fn bitor(&self, rhs: &i64x2) -> i64x2
impl BitXor for i64x2
fn bitxor(&self, rhs: &i64x2) -> i64x2
impl BitNot for i64x2
fn bitnot(&self) -> i64x2
impl Shl<u32> for i64x2
fn shl(&self, rhs: &u32) -> i64x2
impl Shr<u32> for i64x2
fn shr(&self, rhs: &u32) -> i64x2
impl From<Array<i64>> for i64x2
fn from(lanes: Array<i64>) -> i64x2
pub type u8x16 = v128
pub fn splat(a: i32) -> u8x16
pub fn swizzle(&self, indices: &u8x16) -> u8x16
Select each byte by a runtime index; an index of 16 or more yields 0.
pub fn relaxed_swizzle(&self, indices: &u8x16) -> u8x16
Select each byte by a runtime index, leaving an out-of-range one to the engine. Faster where the hardware swizzle differs from Wasm's.
pub fn from_string<S: AsStrSlice>(s: S, offset: i32) -> u8x16
contract 0 <= offset && offset + 16 <= s.len()
Load 16 bytes from a String at the given byte offset into a u8x16.
pub fn store_to_string(&self, s: &mut String)
Append 16 bytes from this u8x16 to a String.
