Skip to main content

UnaryOp

Trait UnaryOp 

Source
pub trait UnaryOp<T>:
    Sealed
    + Copy
    + 'static
where T: NumericElement,
{ // Required methods unsafe fn apply<Arch>( self, v: <Arch as SimdKernel<T>>::Vector, ) -> <Arch as SimdKernel<T>>::Vector where Arch: SimdKernel<T>; fn apply_scalar(self, a: T) -> T; }
Expand description

Sealed ZST trait for single-operand SIMD elementwise operations.

Implementors define how a single vector is transformed (apply) and how a single scalar element is transformed (apply_scalar). Both paths are #[inline(always)] — DCE eliminates unused strategies entirely.

§Zero-Cost Guarantee

Every impl UnaryOp<T> passes through to an #[inline(always)] SimdKernel<T> method. The ZST strategy parameter is erased at every monomorphization site: size_of::<Abs>() == 0.

Required Methods§

Source

unsafe fn apply<Arch>( self, v: <Arch as SimdKernel<T>>::Vector, ) -> <Arch as SimdKernel<T>>::Vector
where Arch: SimdKernel<T>,

Apply the operation to a vector: self.apply::<Arch>(v) -> result.

Takes self by value so Clamp<T> can access its bounds; for true ZST strategies (Abs, Neg, Sqrt), self has size zero and the compiler removes it entirely from the generated code.

§Safety

Processor must support the target feature of Arch.

Source

fn apply_scalar(self, a: T) -> T

Apply the operation to a single scalar element.

Used for the SIMD tail (elements that do not fill a complete vector). Requires only T: Scalar — no unsafe, no vector loads or stores.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> UnaryOp<T> for Abs
where T: NumericElement,

Source§

impl<T> UnaryOp<T> for Clamp<T>

Source§

impl<T> UnaryOp<T> for Neg
where T: NumericElement,

Source§

impl<T> UnaryOp<T> for Popcount
where T: NumericElement,

Source§

impl<T> UnaryOp<T> for RecipSqrt
where T: NumericElement,

Source§

impl<T> UnaryOp<T> for Sqrt
where T: NumericElement,