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].
The number of lanes,
N.Every lane
x.The lanes of
a, in order.The lanes as an array.
The first
Nelements ofs; panics when it has fewer.xs[at..at + N]; panics past the end.xs[at..at + N]set to the lanes; panics past the end.The first
Nelements ofsset to the lanes; panics when it has fewer.Lane
i, ornonepast the last.A copy with lane
iset tox; panics past the last lane.
Sourcepub const fn map<U: SimdElement>(§self, f: fn(T) -> U) -> Simd<U, N> fof each lane.
Sourcepub const fn zip_with<U: SimdElement>(§self, other: Simd<T, N>, f: fn(T, T) -> U) -> Simd<U, N> fof the lanes ofselfandother, pairwise.The lesser lane of each pair; of floats,
other's only where it is less (a NaN inotherkeepsself's lane).The greater lane of each pair, as
mindoes.Each lane kept between
lo's andhi's.Each lane's magnitude (integers wrap at their least value).
The sum of the lanes, added first to last (integers wrap).
The product of the lanes, first to last (integers wrap).
The least lane (the first of equal ones; NaN lanes are skipped unless every lane is one). Panics on zero lanes.
The greatest lane, as
reduce_min.The lanes in reverse order.
Lane
iof the result is lane(i + k) % N: the lanes movedkplaces toward the first.The lanes moved
kplaces toward the last, wrapping around.Lane
iof the result is laneidx[i]ofself; panics on an index past the last lane.The lanes of
selfandothertaken in turn:a0 b0 a1 b1 .., the firstNin the first vector, the rest in the second.The inverse of
interleave: the even lanes ofselfthenother, and the odd ones.The square root of each lane.
self * a + bper lane, rounded once.The square root of each lane.
self * a + bper lane, rounded once.
Trait implementations 30
impl<T: SimdElement, const N: usize> Add for Simd<T, N>impl<T: SimdElement, const N: usize> Add<T> for Simd<T, N>impl<T: SimdElement, const N: usize> Sub for Simd<T, N>impl<T: SimdElement, const N: usize> Sub<T> for Simd<T, N>impl<T: SimdElement, const N: usize> Mul for Simd<T, N>impl<T: SimdElement, const N: usize> Mul<T> for Simd<T, N>impl<T: SimdElement + Div<Output = T>, const N: usize> Div for Simd<T, N>impl<T: SimdElement + Div<Output = T>, const N: usize> Div<T> for Simd<T, N>impl<T: SimdElement + Rem<Output = T>, const N: usize> Rem for Simd<T, N>impl<T: SimdElement, const N: usize> Neg for Simd<T, N>impl<T: SimdElement + BitAnd<Output = T>, const N: usize> BitAnd for Simd<T, N>impl<T: SimdElement + BitOr<Output = T>, const N: usize> BitOr for Simd<T, N>impl<T: SimdElement + BitXor<Output = T>, const N: usize> BitXor for Simd<T, N>impl<T: SimdElement + Not<Output = T>, const N: usize> Not for Simd<T, N>impl<T: SimdElement + Shl<u32, Output = T>, const N: usize> Shl<u32> for Simd<T, N>impl<T: SimdElement + Shr<u32, Output = T>, const N: usize> Shr<u32> for Simd<T, N>impl<T: SimdElement, const N: usize> AddAssign for Simd<T, N>impl<T: SimdElement, const N: usize> SubAssign for Simd<T, N>impl<T: SimdElement, const N: usize> MulAssign for Simd<T, N>impl<T: SimdElement + Div<Output = T>, const N: usize> DivAssign for Simd<T, N>impl<T: SimdElement, const N: usize> DotEq for Simd<T, N>impl<T: SimdElement, const N: usize> DotNe for Simd<T, N>impl<T: SimdElement, const N: usize> DotLt for Simd<T, N>impl<T: SimdElement, const N: usize> DotLe for Simd<T, N>impl<T: SimdElement, const N: usize> DotGt for Simd<T, N>impl<T: SimdElement, const N: usize> DotGe for Simd<T, N>impl<T: SimdElement, const N: usize> Index<usize> for Simd<T, N>impl<T: SimdElement, const N: usize> PartialEq for Simd<T, N>impl<T: SimdElement, const N: usize> Default for Simd<T, N>impl<T: SimdElement, const N: usize> Debug for Simd<T, N>
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.
Every lane set (
true) or clear.Lane
iset wherea[i]istrue.Whether each lane is set.
Whether lane
iis set; panics past the last lane.Whether some lane is set.
Whether every lane is set.
The number of lanes set.
yes's lane where this mask's is set, elseno's.
Trait implementations 6
impl<T: SimdElement, const N: usize> BitAnd for Mask<T, N>impl<T: SimdElement, const N: usize> BitOr for Mask<T, N>impl<T: SimdElement, const N: usize> BitXor for Mask<T, N>impl<T: SimdElement, const N: usize> Not for Mask<T, N>impl<T: SimdElement, const N: usize> PartialEq for Mask<T, N>impl<T: SimdElement, const N: usize> Debug for Mask<T, N>
Traits
SimdElementSource
pub trait SimdElement: Clone + PartialOrd + DebugA primitive number a Simd can hold: every integer type and f32 /
f64.
a + b, wrapping for integers.a - b, wrapping for integers.a * b, wrapping for integers.-a, wrapping for integers (zero for unsigned ones minusa).|a|, wrapping for the least signed integer;aif unsigned.A mask lane: every bit set for
true, clear forfalse.Whether mask lane
ais set.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).