SimdUnaryOp

Trait SimdUnaryOp 

Source
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§

Source

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§

Source

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.

Source

fn map<'dst>( &self, input: &[T], output: &'dst mut [MaybeUninit<T>], ) -> &'dst mut [T]
where Self: Sized, T: GetNumOps,

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.

Source

fn map_mut(&self, input: &mut [T])
where Self: Sized, T: GetNumOps,

Apply a vectorized unary function to a mutable slice.

This is similar to map but reads and writes to the same slice.

Source

fn scalar_eval(&self, x: T) -> T
where Self: Sized, T: GetNumOps,

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.

Implementors§