docs

core::simd

本页内容

API 参考只有英文版,由标准库源代码中的英文文档注释生成。

portable SIMD: Simd<T, N> holds N lanes of a number T, and its operators work on every lane at once. A comparison gives a Mask<T, N>, whose lanes are set or clear.

Where the target has a vector unit for the lanes (x86_64 SSE2 or AVX2, i686 SSE2, arm64 NEON, wasm32 with simd128, ...), an operation on a whole vector is vector code; elsewhere it is the lane loop in its body. Both give the same result: integer + - * wrap, float lanes follow IEEE 754 as the scalar operators do.

Structs

SimdSource

pub struct Simd<T, const N: usize>

N lanes of T, operated on together. A value type, like [T; N].

  • pub const LANES: usize = N§

    Source

    The number of lanes, N.

  • pub const fn splat(x: T) -> Simd<T, N>§

    Source

    Every lane x.

  • pub const fn from_array(a: [T; N]) -> Simd<T, N>§

    Source

    The lanes of a, in order.

  • pub const fn to_array(self) -> [T; N]§

    Source

    The lanes as an array.

  • pub const fn from_slice(s: Slice<T>) -> Simd<T, N>§

    Source

    The first N elements of s; panics when it has fewer.

  • pub const fn load(xs: List<T>, at: usize) -> Simd<T, N>§

    Source

    xs[at..at + N]; panics past the end.

  • pub const fn store(self, xs: List<T>, at: usize)§

    Source

    xs[at..at + N] set to the lanes; panics past the end.

  • pub const fn copy_to(self, s: SliceMut<T>)§

    Source

    The first N elements of s set to the lanes; panics when it has fewer.

  • pub const fn get(self, i: usize) -> T | none§

    Source

    Lane i, or none past the last.

  • pub const fn with_lane(self, i: usize, x: T) -> Simd<T, N>§

    Source

    A copy with lane i set to x; panics past the last lane.

  • pub const fn map<U: SimdElement>(self, f: fn(T) -> U) -> Simd<U, N>§

    Source

    f of each lane.

  • pub const fn zip_with<U: SimdElement>(self, other: Simd<T, N>, f: fn(T, T) -> U) -> Simd<U, N>§

    Source

    f of the lanes of self and other, pairwise.

  • pub const fn min(self, other: Simd<T, N>) -> Simd<T, N>§

    Source

    The lesser lane of each pair; of floats, other's only where it is less (a NaN in other keeps self's lane).

  • pub const fn max(self, other: Simd<T, N>) -> Simd<T, N>§

    Source

    The greater lane of each pair, as min does.

  • pub const fn clamp(self, lo: Simd<T, N>, hi: Simd<T, N>) -> Simd<T, N>§

    Source

    Each lane kept between lo's and hi's.

  • pub const fn abs(self) -> Simd<T, N>§

    Source

    Each lane's magnitude (integers wrap at their least value).

  • pub const fn reduce_sum(self) -> T§

    Source

    The sum of the lanes, added first to last (integers wrap).

  • pub const fn reduce_product(self) -> T§

    Source

    The product of the lanes, first to last (integers wrap).

  • pub const fn reduce_min(self) -> T§

    Source

    The least lane (the first of equal ones; NaN lanes are skipped unless every lane is one). Panics on zero lanes.

  • pub const fn reduce_max(self) -> T§

    Source

    The greatest lane, as reduce_min.

  • pub const fn reverse(self) -> Simd<T, N>§

    Source

    The lanes in reverse order.

  • pub const fn rotate_left(self, k: usize) -> Simd<T, N>§

    Source

    Lane i of the result is lane (i + k) % N: the lanes moved k places toward the first.

  • pub const fn rotate_right(self, k: usize) -> Simd<T, N>§

    Source

    The lanes moved k places toward the last, wrapping around.

  • pub const fn swizzle(self, idx: [usize; N]) -> Simd<T, N>§

    Source

    Lane i of the result is lane idx[i] of self; panics on an index past the last lane.

  • pub const fn interleave(self, other: Simd<T, N>) -> (Simd<T, N>, Simd<T, N>)§

    Source

    The lanes of self and other taken in turn: a0 b0 a1 b1 .., the first N in the first vector, the rest in the second.

  • pub const fn deinterleave(self, other: Simd<T, N>) -> (Simd<T, N>, Simd<T, N>)§

    Source

    The inverse of interleave: the even lanes of self then other, and the odd ones.

  • pub const fn sqrt(self) -> Simd<f32, N>§

    Source

    The square root of each lane.

  • pub const fn mul_add(self, a: Simd<f32, N>, b: Simd<f32, N>) -> Simd<f32, N>§

    Source

    self * a + b per lane, rounded once.

  • pub const fn sqrt(self) -> Simd<f64, N>§

    Source

    The square root of each lane.

  • pub const fn mul_add(self, a: Simd<f64, N>, b: Simd<f64, N>) -> Simd<f64, N>§

    Source

    self * a + b per lane, rounded once.

Trait implementations 30

MaskSource

pub struct Mask<T, const N: usize>

The lanes of a comparison of Simd<T, N>s: each set or clear. select picks lanes by it; any / all test it.

  • pub const fn splat(on: bool) -> Mask<T, N>§

    Source

    Every lane set (true) or clear.

  • pub const fn from_array(a: [bool; N]) -> Mask<T, N>§

    Source

    Lane i set where a[i] is true.

  • pub const fn to_array(self) -> [bool; N]§

    Source

    Whether each lane is set.

  • pub const fn test(self, i: usize) -> bool§

    Source

    Whether lane i is set; panics past the last lane.

  • pub const fn any(self) -> bool§

    Source

    Whether some lane is set.

  • pub const fn all(self) -> bool§

    Source

    Whether every lane is set.

  • pub const fn count(self) -> usize§

    Source

    The number of lanes set.

  • pub const fn select(self, yes: Simd<T, N>, no: Simd<T, N>) -> Simd<T, N>§

    Source

    yes's lane where this mask's is set, else no's.

Trait implementations 6

Traits

SimdElementSource

pub trait SimdElement: Clone + PartialOrd + Debug

A primitive number a Simd can hold: every integer type and f32 / f64.

  • fn lane_add(a: Self, b: Self) -> Self§

    Source

    a + b, wrapping for integers.

  • fn lane_sub(a: Self, b: Self) -> Self§

    Source

    a - b, wrapping for integers.

  • fn lane_mul(a: Self, b: Self) -> Self§

    Source

    a * b, wrapping for integers.

  • fn lane_neg(a: Self) -> Self§

    Source

    -a, wrapping for integers (zero for unsigned ones minus a).

  • fn lane_abs(a: Self) -> Self§

    Source

    |a|, wrapping for the least signed integer; a if unsigned.

  • fn lane_mask(on: bool) -> Self§

    Source

    A mask lane: every bit set for true, clear for false.

  • fn lane_on(a: Self) -> bool§

    Source

    Whether mask lane a is set.

  • fn lane_zero() -> Self§

    Source

    Zero.

Type aliases

f32x2Source

pub type f32x2 = Simd<f32, 2>

2 lanes of f32 (8 bytes).

f32x4Source

pub type f32x4 = Simd<f32, 4>

4 lanes of f32 (16 bytes).

f32x8Source

pub type f32x8 = Simd<f32, 8>

8 lanes of f32 (32 bytes).

f32x16Source

pub type f32x16 = Simd<f32, 16>

16 lanes of f32 (64 bytes).

f64x2Source

pub type f64x2 = Simd<f64, 2>

2 lanes of f64 (16 bytes).

f64x4Source

pub type f64x4 = Simd<f64, 4>

4 lanes of f64 (32 bytes).

f64x8Source

pub type f64x8 = Simd<f64, 8>

8 lanes of f64 (64 bytes).

i8x16Source

pub type i8x16 = Simd<i8, 16>

16 lanes of i8 (16 bytes).

i8x32Source

pub type i8x32 = Simd<i8, 32>

32 lanes of i8 (32 bytes).

i16x8Source

pub type i16x8 = Simd<i16, 8>

8 lanes of i16 (16 bytes).

i16x16Source

pub type i16x16 = Simd<i16, 16>

16 lanes of i16 (32 bytes).

i32x4Source

pub type i32x4 = Simd<i32, 4>

4 lanes of i32 (16 bytes).

i32x8Source

pub type i32x8 = Simd<i32, 8>

8 lanes of i32 (32 bytes).

i64x2Source

pub type i64x2 = Simd<i64, 2>

2 lanes of i64 (16 bytes).

i64x4Source

pub type i64x4 = Simd<i64, 4>

4 lanes of i64 (32 bytes).

u8x16Source

pub type u8x16 = Simd<u8, 16>

16 lanes of u8 (16 bytes).

u8x32Source

pub type u8x32 = Simd<u8, 32>

32 lanes of u8 (32 bytes).

u16x8Source

pub type u16x8 = Simd<u16, 8>

8 lanes of u16 (16 bytes).

u16x16Source

pub type u16x16 = Simd<u16, 16>

16 lanes of u16 (32 bytes).

u32x4Source

pub type u32x4 = Simd<u32, 4>

4 lanes of u32 (16 bytes).

u32x8Source

pub type u32x8 = Simd<u32, 8>

8 lanes of u32 (32 bytes).

u64x2Source

pub type u64x2 = Simd<u64, 2>

2 lanes of u64 (16 bytes).

u64x4Source

pub type u64x4 = Simd<u64, 4>

4 lanes of u64 (32 bytes).