pub trait SimdReal<R: Real, const N: usize>where
LaneCount<N>: SupportedLaneCount,
for<'a> Self: Send + Sync + Clone + Copy + Default + ApproxEq<R, Self> + PartialEq + PartialOrd + Debug + From<Simd<R, N>> + Into<Simd<R, N>> + From<[R; N]> + Into<[R; N]> + AsRef<[R; N]> + AsMut<[R; N]> + Product<Self> + Sum<Self> + Product<&'a Self> + Sum<&'a Self> + Index<usize, Output = R> + IndexMut<usize, Output = R> + Select<Self::Mask> + Add<Output = Self> + AddAssign + Sub<Output = Self> + SubAssign + Mul<Output = Self> + MulAssign + Div<Output = Self> + DivAssign + Rem<Output = Self> + RemAssign + Add<&'a Self, Output = Self> + AddAssign<&'a Self> + Sub<&'a Self, Output = Self> + SubAssign<&'a Self> + Mul<&'a Self, Output = Self> + MulAssign<&'a Self> + Div<&'a Self, Output = Self> + DivAssign<&'a Self> + Rem<&'a Self, Output = Self> + RemAssign<&'a Self> + Neg<Output = Self>,{
type Bits: SimdBits<R::Bits, N, Mask = Self::Mask>;
type Mask: SimdMask<N>;
const N: usize = N;
Show 59 methods
// Required methods
fn splat(value: R) -> Self;
fn as_array(&self) -> &[R; N];
fn as_mut_array(&mut self) -> &mut [R; N];
fn from_array(array: [R; N]) -> Self;
fn to_array(self) -> [R; N];
fn from_slice(slice: &[R]) -> Self;
fn gather_or(slice: &[R], idxs: Simd<usize, N>, or: Self) -> Self
where LaneCount<N>: SupportedLaneCount;
fn gather_or_default(slice: &[R], idxs: Simd<usize, N>) -> Self
where R: Default,
LaneCount<N>: SupportedLaneCount;
fn gather_select(
slice: &[R],
enable: Mask<isize, N>,
idxs: Simd<usize, N>,
or: Self
) -> Self
where LaneCount<N>: SupportedLaneCount;
fn scatter(self, slice: &mut [R], idxs: Simd<usize, N>)
where LaneCount<N>: SupportedLaneCount;
fn scatter_select(
self,
slice: &mut [R],
enable: Mask<isize, N>,
idxs: Simd<usize, N>
)
where LaneCount<N>: SupportedLaneCount;
fn from_bits(bits: Self::Bits) -> Self;
fn to_bits(self) -> Self::Bits;
fn reduce_sum(self) -> R;
fn reduce_product(self) -> R;
fn reduce_min(self) -> R;
fn reduce_max(self) -> R;
fn reverse(self) -> Self;
fn simd_rotate_left<const OFFSET: usize>(self) -> Self;
fn simd_rotate_right<const OFFSET: usize>(self) -> Self;
fn interleave(self, other: Self) -> (Self, Self);
fn deinterleave(self, other: Self) -> (Self, Self);
fn swizzle<T: Swizzle<N>>(self) -> Self;
fn concat_swizzle<T: Swizzle<N>>(self, other: Self) -> Self;
fn simd_eq(self, other: Self) -> Self::Mask;
fn simd_ne(self, other: Self) -> Self::Mask;
fn simd_lt(self, other: Self) -> Self::Mask;
fn simd_gt(self, other: Self) -> Self::Mask;
fn simd_le(self, other: Self) -> Self::Mask;
fn simd_ge(self, other: Self) -> Self::Mask;
fn is_sign_positive(self) -> Self::Mask;
fn is_sign_negative(self) -> Self::Mask;
fn is_nan(self) -> Self::Mask;
fn is_infinite(self) -> Self::Mask;
fn is_finite(self) -> Self::Mask;
fn is_subnormal(self) -> Self::Mask;
fn is_normal(self) -> Self::Mask;
fn abs(self) -> Self;
fn signum(self) -> Self;
fn copysign(self, sign: Self) -> Self;
fn simd_min(self, other: Self) -> Self;
fn simd_max(self, other: Self) -> Self;
fn simd_clamp(self, min: Self, max: Self) -> Self;
fn recip(self) -> Self;
fn to_degrees(self) -> Self;
fn to_radians(self) -> Self;
fn mul_add(self, a: Self, b: Self) -> Self;
fn sqrt(self) -> Self;
fn floor(self) -> Self;
fn ceil(self) -> Self;
fn round(self) -> Self;
fn trunc(self) -> Self;
fn fract(self) -> Self;
// Provided methods
fn len(&self) -> usize { ... }
fn insert(self, lane: usize, value: R) -> Self { ... }
fn simd_approx_eq(
self,
other: Self,
epsilon: Self,
ulp: Self::Bits
) -> Self::Mask { ... }
fn simd_approx_ne(
self,
other: Self,
epsilon: Self,
ulp: Self::Bits
) -> Self::Mask { ... }
fn mask_from_array(array: [bool; N]) -> Self::Mask { ... }
fn mask_flag(lane: usize, value: bool) -> Self::Mask { ... }
}
Expand description
Real number vector of Simd<f32, N>
or Simd<f64, N>
with associated SimdBits
and SimdMask
vector.
Required Associated Types§
Provided Associated Constants§
Required Methods§
sourcefn as_mut_array(&mut self) -> &mut [R; N]
fn as_mut_array(&mut self) -> &mut [R; N]
Returns a mutable array reference containing the entire SIMD vector.
sourcefn from_array(array: [R; N]) -> Self
fn from_array(array: [R; N]) -> Self
Converts an array to a SIMD vector.
sourcefn from_slice(slice: &[R]) -> Self
fn from_slice(slice: &[R]) -> Self
Converts a slice to a SIMD vector containing slice[..N]
Panics
Panics if the slice’s len
is less than the vector’s Simd::N
.
sourcefn gather_or(slice: &[R], idxs: Simd<usize, N>, or: Self) -> Selfwhere
LaneCount<N>: SupportedLaneCount,
fn gather_or(slice: &[R], idxs: Simd<usize, N>, or: Self) -> Selfwhere
LaneCount<N>: SupportedLaneCount,
Reads from potentially discontiguous indices in slice
to construct a SIMD vector.
If an index is out-of-bounds, the lane is instead selected from the or
vector.
sourcefn gather_or_default(slice: &[R], idxs: Simd<usize, N>) -> Self
fn gather_or_default(slice: &[R], idxs: Simd<usize, N>) -> Self
Reads from potentially discontiguous indices in slice
to construct a SIMD vector.
If an index is out-of-bounds, the lane is set to the default value for the type.
sourcefn gather_select(
slice: &[R],
enable: Mask<isize, N>,
idxs: Simd<usize, N>,
or: Self
) -> Selfwhere
LaneCount<N>: SupportedLaneCount,
fn gather_select(
slice: &[R],
enable: Mask<isize, N>,
idxs: Simd<usize, N>,
or: Self
) -> Selfwhere
LaneCount<N>: SupportedLaneCount,
Reads from potentially discontiguous indices in slice
to construct a SIMD vector.
The mask enable
s all true
lanes and disables all false
lanes.
If an index is disabled or is out-of-bounds, the lane is selected from the or
vector.
sourcefn scatter(self, slice: &mut [R], idxs: Simd<usize, N>)where
LaneCount<N>: SupportedLaneCount,
fn scatter(self, slice: &mut [R], idxs: Simd<usize, N>)where
LaneCount<N>: SupportedLaneCount,
Writes the values in a SIMD vector to potentially discontiguous indices in slice
.
If two lanes in the scattered vector would write to the same index only the last lane is guaranteed to actually be written.
sourcefn scatter_select(
self,
slice: &mut [R],
enable: Mask<isize, N>,
idxs: Simd<usize, N>
)where
LaneCount<N>: SupportedLaneCount,
fn scatter_select(
self,
slice: &mut [R],
enable: Mask<isize, N>,
idxs: Simd<usize, N>
)where
LaneCount<N>: SupportedLaneCount,
Writes the values in a SIMD vector to multiple potentially discontiguous indices in slice
.
The mask enable
s all true
lanes and disables all false
lanes. If an enabled index is
out-of-bounds, the lane is not written. If two enabled lanes in the scattered vector would
write to the same index, only the last lane is guaranteed to actually be written.
sourcefn from_bits(bits: Self::Bits) -> Self
fn from_bits(bits: Self::Bits) -> Self
Raw transmutation from an unsigned integer vector type with the same size and number of lanes.
sourcefn to_bits(self) -> Self::Bits
fn to_bits(self) -> Self::Bits
Raw transmutation to an unsigned integer vector type with the same size and number of lanes.
sourcefn reduce_sum(self) -> R
fn reduce_sum(self) -> R
Reducing wrapping add. Returns the sum of the lanes of the vector, with wrapping addition.
sourcefn reduce_product(self) -> R
fn reduce_product(self) -> R
Reducing wrapping multiply. Returns the product of the lanes of the vector, with wrapping multiplication.
sourcefn reduce_min(self) -> R
fn reduce_min(self) -> R
Reducing minimum. Returns the minimum lane in the vector.
Returns values based on equality, so a vector containing both 0.0
and -0.0
may return
either. This function will not return NaN unless all lanes are NaN.
sourcefn reduce_max(self) -> R
fn reduce_max(self) -> R
Reducing maximum. Returns the maximum lane in the vector.
Returns values based on equality, so a vector containing both 0.0
and -0.0
may return
either. This function will not return NaN unless all lanes are NaN.
sourcefn simd_rotate_left<const OFFSET: usize>(self) -> Self
fn simd_rotate_left<const OFFSET: usize>(self) -> Self
Rotates the vector such that the first OFFSET
lanes of the slice move to the end while
the last Self::N - OFFSET
lanes move to the front. The lane previously in lane
OFFSET
will become the first lane in the slice.
sourcefn simd_rotate_right<const OFFSET: usize>(self) -> Self
fn simd_rotate_right<const OFFSET: usize>(self) -> Self
Rotates the vector such that the first Self::N - OFFSET
lanes of the vector move to
the end while the last OFFSET
lanes move to the front. The lane previously at index
Self::N - OFFSET
will become the first lane in the slice.
sourcefn interleave(self, other: Self) -> (Self, Self)
fn interleave(self, other: Self) -> (Self, Self)
Interleaves two vectors.
Produces two vectors with lanes taken alternately from self
and other
.
The first result contains the first Self::N / 2
lanes from self
and other
,
alternating, starting with the first lane of self
.
The second result contains the last Self::N / 2
lanes from self
and other
,
alternating, starting with the lane Self::N / 2
from the start of self
.
sourcefn deinterleave(self, other: Self) -> (Self, Self)
fn deinterleave(self, other: Self) -> (Self, Self)
Deinterleaves two vectors.
The first result takes every other lane of self
and then other
, starting with the first
lane.
The second result takes every other lane of self
and then other
, starting with the
second lane.
sourcefn swizzle<T: Swizzle<N>>(self) -> Self
fn swizzle<T: Swizzle<N>>(self) -> Self
Creates new vector by copying lanes from selected lanes of self
.
sourcefn concat_swizzle<T: Swizzle<N>>(self, other: Self) -> Self
fn concat_swizzle<T: Swizzle<N>>(self, other: Self) -> Self
Creates new vector by copying lanes from selected lanes of self
and other
.
sourcefn simd_eq(self, other: Self) -> Self::Mask
fn simd_eq(self, other: Self) -> Self::Mask
Test if each lane is equal to the corresponding lane in other
.
sourcefn simd_ne(self, other: Self) -> Self::Mask
fn simd_ne(self, other: Self) -> Self::Mask
Test if each lane is not equal to the corresponding lane in other
.
sourcefn simd_lt(self, other: Self) -> Self::Mask
fn simd_lt(self, other: Self) -> Self::Mask
Test if each lane is less than the corresponding lane in other
.
sourcefn simd_gt(self, other: Self) -> Self::Mask
fn simd_gt(self, other: Self) -> Self::Mask
Test if each lane is greater than the corresponding lane in other
.
sourcefn simd_le(self, other: Self) -> Self::Mask
fn simd_le(self, other: Self) -> Self::Mask
Test if each lane is less than or equal to the corresponding lane in other
.
sourcefn simd_ge(self, other: Self) -> Self::Mask
fn simd_ge(self, other: Self) -> Self::Mask
Test if each lane is greater than or equal to the corresponding lane in other
.
sourcefn is_sign_positive(self) -> Self::Mask
fn is_sign_positive(self) -> Self::Mask
Returns true for each lane if it has a positive sign, including +0.0
, NaNs with positive
sign bit and positive infinity.
sourcefn is_sign_negative(self) -> Self::Mask
fn is_sign_negative(self) -> Self::Mask
Returns true for each lane if it has a negative sign, including -0.0
, NaNs with negative
sign bit and negative infinity.
sourcefn is_infinite(self) -> Self::Mask
fn is_infinite(self) -> Self::Mask
Returns true for each lane if its value is positive infinity or negative infinity.
sourcefn is_finite(self) -> Self::Mask
fn is_finite(self) -> Self::Mask
Returns true for each lane if its value is neither infinite nor NaN.
sourcefn is_subnormal(self) -> Self::Mask
fn is_subnormal(self) -> Self::Mask
Returns true for each lane if its value is subnormal.
sourcefn is_normal(self) -> Self::Mask
fn is_normal(self) -> Self::Mask
Returns true for each lane if its value is neither neither zero, infinite, subnormal, or NaN.
sourcefn abs(self) -> Self
fn abs(self) -> Self
Produces a vector where every lane has the absolute value of the equivalently-indexed lane
in self
.
sourcefn signum(self) -> Self
fn signum(self) -> Self
Replaces each lane with a number that represents its sign.
- returns
1.0
if the number is positive,+0.0
, orReal::INFINITY
. - returns
-1.0
if the number is negative,-0.0
, orReal::NEG_INFINITY
. - returns
Real::NAN
if the number is NaN.
sourcefn simd_min(self, other: Self) -> Self
fn simd_min(self, other: Self) -> Self
Returns the minimum of each lane.
If one of the values is Real::NAN
, then the other value is returned.
sourcefn simd_max(self, other: Self) -> Self
fn simd_max(self, other: Self) -> Self
Returns the maximum of each lane.
If one of the values is Real::NAN
, then the other value is returned.
sourcefn simd_clamp(self, min: Self, max: Self) -> Self
fn simd_clamp(self, min: Self, max: Self) -> Self
Restrict each lane to a certain interval unless it is NaN.
For each lane in self
, returns the corresponding lane in max
if the lane is
greater than max
, and the corresponding lane in min
if the lane is less
than min
. Otherwise returns the lane in self
.
sourcefn to_degrees(self) -> Self
fn to_degrees(self) -> Self
Converts each lane from radians to degrees.
sourcefn to_radians(self) -> Self
fn to_radians(self) -> Self
Converts each lane from degrees to radians.
sourcefn mul_add(self, a: Self, b: Self) -> Self
fn mul_add(self, a: Self, b: Self) -> Self
Fused multiply-add. Computes (self * a) + b
with only one rounding error, yielding a more
accurate result than an unfused multiply-add.
Using mul_add
may be more performant than an unfused multiply-add if the target
architecture has a dedicated fma
CPU instruction. However, this is not always true, and
will be heavily dependant on designing algorithms with specific target hardware in mind.
sourcefn sqrt(self) -> Self
fn sqrt(self) -> Self
Produces a vector where every lane has the square root value of the equivalently-indexed
lane in self
Provided Methods§
sourcefn simd_approx_eq(
self,
other: Self,
epsilon: Self,
ulp: Self::Bits
) -> Self::Mask
fn simd_approx_eq( self, other: Self, epsilon: Self, ulp: Self::Bits ) -> Self::Mask
Tests lanes for approximate equality wrt epsilon
or ulp
, “or” in the sense of ||
.
sourcefn simd_approx_ne(
self,
other: Self,
epsilon: Self,
ulp: Self::Bits
) -> Self::Mask
fn simd_approx_ne( self, other: Self, epsilon: Self, ulp: Self::Bits ) -> Self::Mask
Tests lanes for approximate inequality wrt epsilon
and ulp
, “and” in the sense of &&
.
sourcefn mask_from_array(array: [bool; N]) -> Self::Mask
fn mask_from_array(array: [bool; N]) -> Self::Mask
Converts an array to a SIMD vector mask.