pub trait SimdBehaviour<const N: usize>: Constructwhere
VecLen<N>: SupportedVecLen,{
type VectorRepr: SoundVectorRepr<N, Self>;
Show 19 methods
// Provided methods
fn vec_from_array(array: [Self; N]) -> Vector<N, Self, Simd>
where Self: Scalar { ... }
fn vec_splat(value: Self) -> Vector<N, Self, Simd>
where Self: Scalar { ... }
unsafe fn vec_swizzle2<const X_SRC: usize, const Y_SRC: usize>(
vec: Vector<N, Self, Simd>,
) -> Vector<2, Self, Simd>
where Self: Scalar { ... }
unsafe fn vec_swizzle3<const X_SRC: usize, const Y_SRC: usize, const Z_SRC: usize>(
vec: Vector<N, Self, Simd>,
) -> Vector<3, Self, Simd>
where Self: Scalar { ... }
unsafe fn vec_swizzle4<const X_SRC: usize, const Y_SRC: usize, const Z_SRC: usize, const W_SRC: usize>(
vec: Vector<N, Self, Simd>,
) -> Vector<4, Self, Simd>
where Self: Scalar { ... }
fn vec_eq(vec: Vector<N, Self, Simd>, other: Vector<N, Self, Simd>) -> bool
where Self: Scalar + PartialEq { ... }
fn vec_ne(vec: Vector<N, Self, Simd>, other: Vector<N, Self, Simd>) -> bool
where Self: Scalar + PartialEq { ... }
fn vec_neg(vec: Vector<N, Self, Simd>) -> Vector<N, Self, Simd>
where Self: Scalar + Neg<Output = Self> { ... }
fn vec_not(vec: Vector<N, Self, Simd>) -> Vector<N, Self, Simd>
where Self: Scalar + Not<Output = Self> { ... }
fn vec_add(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
where Self: Scalar + Add<Output = Self> { ... }
fn vec_sub(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
where Self: Scalar + Sub<Output = Self> { ... }
fn vec_mul(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
where Self: Scalar + Mul<Output = Self> { ... }
fn vec_div(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
where Self: Scalar + Div<Output = Self> { ... }
fn vec_rem(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
where Self: Scalar + Rem<Output = Self> { ... }
fn vec_shl(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
where Self: Scalar + Shl<Output = Self> { ... }
fn vec_shr(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
where Self: Scalar + Shr<Output = Self> { ... }
fn vec_bitand(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
where Self: Scalar + BitAnd<Output = Self> { ... }
fn vec_bitor(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
where Self: Scalar + BitOr<Output = Self> { ... }
fn vec_bitxor(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
where Self: Scalar + BitXor<Output = Self> { ... }
}Expand description
Controls the implementation details of Vector<N, Self, Simd>. For
example, f32 implementing SimdBehaviour<4> controls
Vector<4, f32, Simd>.
The goal of implementing this trait is to enable SIMD optimizations, but it’s acceptable not to use SIMD if it doesn’t provide a performance benefit, or if it’s only a placeholder implementation.
Required Associated Types§
Sourcetype VectorRepr: SoundVectorRepr<N, Self>
type VectorRepr: SoundVectorRepr<N, Self>
The internal representation of the vector.
There are two ways to define the internal representation:
-
Array:
If the internal representation is[Self; N], there is no SIMD alignment.
In this case, the behavior ofSimdandNonSimdis the same, with no SIMD optimizations. -
Wrapped Vector Type:
IfSelfis a wrapper around an existing scalar type,
the internal representation can be a vector of that scalar type.
This allows you to leverage the SIMD-optimized API of the base type.
To enable this,Selfmust implementScalarWrapper<TInner>.
§Example
use ggmath::*;
#[repr(transparent)]
#[derive(Copy, Clone)]
struct CustomScalar(f32);
impl Scalar for CustomScalar {}
// SAFETY: CustomScalar is a direct wrapper around f32, so it's safe to
// implement ScalarWrapper<f32> for it.
unsafe impl ScalarWrapper<f32> for CustomScalar {}
impl<const N: usize> SimdBehaviour<N> for CustomScalar
where
VecLen<N>: SupportedVecLen,
{
type VectorRepr = Vector<N, f32, Simd>;
// Now you can use f32's SIMD-optimized vector API to optimize your vector
// implementation.
}Provided Methods§
Sourcefn vec_from_array(array: [Self; N]) -> Vector<N, Self, Simd>where
Self: Scalar,
fn vec_from_array(array: [Self; N]) -> Vector<N, Self, Simd>where
Self: Scalar,
Overridable implementation of Vector::from_array.
Sourcefn vec_splat(value: Self) -> Vector<N, Self, Simd>where
Self: Scalar,
fn vec_splat(value: Self) -> Vector<N, Self, Simd>where
Self: Scalar,
Overridable implementation of Vector::splat.
Sourceunsafe fn vec_swizzle2<const X_SRC: usize, const Y_SRC: usize>(
vec: Vector<N, Self, Simd>,
) -> Vector<2, Self, Simd>where
Self: Scalar,
unsafe fn vec_swizzle2<const X_SRC: usize, const Y_SRC: usize>(
vec: Vector<N, Self, Simd>,
) -> Vector<2, Self, Simd>where
Self: Scalar,
Overridable implementation of Vector::swizzle2.
Sourceunsafe fn vec_swizzle3<const X_SRC: usize, const Y_SRC: usize, const Z_SRC: usize>(
vec: Vector<N, Self, Simd>,
) -> Vector<3, Self, Simd>where
Self: Scalar,
unsafe fn vec_swizzle3<const X_SRC: usize, const Y_SRC: usize, const Z_SRC: usize>(
vec: Vector<N, Self, Simd>,
) -> Vector<3, Self, Simd>where
Self: Scalar,
Overridable implementation of Vector::swizzle3.
Sourceunsafe fn vec_swizzle4<const X_SRC: usize, const Y_SRC: usize, const Z_SRC: usize, const W_SRC: usize>(
vec: Vector<N, Self, Simd>,
) -> Vector<4, Self, Simd>where
Self: Scalar,
unsafe fn vec_swizzle4<const X_SRC: usize, const Y_SRC: usize, const Z_SRC: usize, const W_SRC: usize>(
vec: Vector<N, Self, Simd>,
) -> Vector<4, Self, Simd>where
Self: Scalar,
Overridable implementation of Vector::swizzle4.
Sourcefn vec_eq(vec: Vector<N, Self, Simd>, other: Vector<N, Self, Simd>) -> bool
fn vec_eq(vec: Vector<N, Self, Simd>, other: Vector<N, Self, Simd>) -> bool
Overridable implementation of Vector::eq.
Sourcefn vec_ne(vec: Vector<N, Self, Simd>, other: Vector<N, Self, Simd>) -> bool
fn vec_ne(vec: Vector<N, Self, Simd>, other: Vector<N, Self, Simd>) -> bool
Overridable implementation of Vector::ne.
Sourcefn vec_neg(vec: Vector<N, Self, Simd>) -> Vector<N, Self, Simd>
fn vec_neg(vec: Vector<N, Self, Simd>) -> Vector<N, Self, Simd>
Overridable implementation of Vector::neg.
Implementations may deviate from Self as Neg in edge cases, but should
otherwise closely follow the behavior of Self as Neg.
Sourcefn vec_not(vec: Vector<N, Self, Simd>) -> Vector<N, Self, Simd>
fn vec_not(vec: Vector<N, Self, Simd>) -> Vector<N, Self, Simd>
Overridable implementation of Vector::not.
Implementations may deviate from Self as Not in edge cases, but should
otherwise closely follow the behavior of Self as Not.
Sourcefn vec_add(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
fn vec_add( vec: Vector<N, Self, Simd>, rhs: Vector<N, Self, Simd>, ) -> Vector<N, Self, Simd>
Overridable implementation of Vector::add.
Implementations may deviate from Self as Add in edge cases, but should
otherwise closely follow the behavior of Self as Add.
Sourcefn vec_sub(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
fn vec_sub( vec: Vector<N, Self, Simd>, rhs: Vector<N, Self, Simd>, ) -> Vector<N, Self, Simd>
Overridable implementation of Vector::sub.
Implementations may deviate from Self as Sub in edge cases, but should
otherwise closely follow the behavior of Self as Sub.
Sourcefn vec_mul(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
fn vec_mul( vec: Vector<N, Self, Simd>, rhs: Vector<N, Self, Simd>, ) -> Vector<N, Self, Simd>
Overridable implementation of Vector::mul.
Implementations may deviate from Self as Mul in edge cases, but should
otherwise closely follow the behavior of Self as Mul.
Sourcefn vec_div(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
fn vec_div( vec: Vector<N, Self, Simd>, rhs: Vector<N, Self, Simd>, ) -> Vector<N, Self, Simd>
Overridable implementation of Vector::div.
Implementations may deviate from Self as Div in edge cases, but should
otherwise closely follow the behavior of Self as Div.
Sourcefn vec_rem(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
fn vec_rem( vec: Vector<N, Self, Simd>, rhs: Vector<N, Self, Simd>, ) -> Vector<N, Self, Simd>
Overridable implementation of Vector::rem.
Implementations may deviate from Self as Rem in edge cases, but should
otherwise closely follow the behavior of Self as Rem.
Sourcefn vec_shl(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
fn vec_shl( vec: Vector<N, Self, Simd>, rhs: Vector<N, Self, Simd>, ) -> Vector<N, Self, Simd>
Overridable implementation of Vector::shl.
Implementations may deviate from Self as Shl in edge cases, but should
otherwise closely follow the behavior of Self as Shl.
Sourcefn vec_shr(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
fn vec_shr( vec: Vector<N, Self, Simd>, rhs: Vector<N, Self, Simd>, ) -> Vector<N, Self, Simd>
Overridable implementation of Vector::shr.
Implementations may deviate from Self as Shr in edge cases, but should
otherwise closely follow the behavior of Self as Shr.
Sourcefn vec_bitand(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
fn vec_bitand( vec: Vector<N, Self, Simd>, rhs: Vector<N, Self, Simd>, ) -> Vector<N, Self, Simd>
Overridable implementation of Vector::bitand.
Implementations may deviate from Self as BitAnd in edge cases, but should
otherwise closely follow the behavior of Self as BitAnd.
Sourcefn vec_bitor(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
fn vec_bitor( vec: Vector<N, Self, Simd>, rhs: Vector<N, Self, Simd>, ) -> Vector<N, Self, Simd>
Overridable implementation of Vector::bitor.
Implementations may deviate from Self as BitOr in edge cases, but should
otherwise closely follow the behavior of Self as BitOr.
Sourcefn vec_bitxor(
vec: Vector<N, Self, Simd>,
rhs: Vector<N, Self, Simd>,
) -> Vector<N, Self, Simd>
fn vec_bitxor( vec: Vector<N, Self, Simd>, rhs: Vector<N, Self, Simd>, ) -> Vector<N, Self, Simd>
Overridable implementation of Vector::bitxor.
Implementations may deviate from Self as BitXor in edge cases, but should
otherwise closely follow the behavior of Self as BitXor.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.