pub trait SimdUnaryOp<T: GetSimd> {
// Required method
fn eval<I: Isa>(&self, isa: I, x: T::Simd<I>) -> T::Simd<I>;
// Provided methods
fn apply<I: Isa>(isa: I, x: T::Simd<I>) -> T::Simd<I>
where Self: Default { ... }
fn map<'dst>(
&self,
input: &[T],
output: &'dst mut [MaybeUninit<T>],
) -> &'dst mut [T]
where Self: Sized,
T: GetNumOps { ... }
fn map_mut(&self, input: &mut [T])
where Self: Sized,
T: GetNumOps { ... }
fn scalar_eval(&self, x: T) -> T
where Self: Sized,
T: GetNumOps { ... }
}Expand description
Convenience trait for defining vectorized unary operations.
Required Methods§
Sourcefn eval<I: Isa>(&self, isa: I, x: T::Simd<I>) -> T::Simd<I>
fn eval<I: Isa>(&self, isa: I, x: T::Simd<I>) -> T::Simd<I>
Evaluate the unary function on the elements in x.
use rten_simd::{Isa, Simd, SimdUnaryOp};
use rten_simd::ops::{FloatOps, NumOps};
struct Reciprocal {}
impl SimdUnaryOp<f32> for Reciprocal {
fn eval<I: Isa>(&self, isa: I, x: I::F32) -> I::F32 {
let ops = isa.f32();
ops.div(ops.one(), x)
}
}Provided Methods§
Sourcefn apply<I: Isa>(isa: I, x: T::Simd<I>) -> T::Simd<I>where
Self: Default,
fn apply<I: Isa>(isa: I, x: T::Simd<I>) -> T::Simd<I>where
Self: Default,
Evaluate the unary function on elements in x.
This is a shorthand for Self::default().eval(x). It is mainly useful
when one vectorized operation needs to call another as part of its
implementation.
Sourcefn map<'dst>(
&self,
input: &[T],
output: &'dst mut [MaybeUninit<T>],
) -> &'dst mut [T]
fn map<'dst>( &self, input: &[T], output: &'dst mut [MaybeUninit<T>], ) -> &'dst mut [T]
Apply this function to a slice.
This reads elements from input in SIMD vector-sized chunks, applies
the operation and writes the results to output.
Sourcefn map_mut(&self, input: &mut [T])
fn map_mut(&self, input: &mut [T])
Apply a vectorized unary function to a mutable slice.
This is similar to map but reads and writes
to the same slice.
Sourcefn scalar_eval(&self, x: T) -> T
fn scalar_eval(&self, x: T) -> T
Apply this operation to a single element.
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.