Skip to main content

SimdFloatElement

Trait SimdFloatElement 

Source
pub trait SimdFloatElement:
    SimdElement
    + Neg<Output = Self>
    + From<i8>
    + From<u8> {
    type Native<S: Simd>: SimdFloat<S, Element = Self>;
}
Expand description

Types that can be used as elements in float SIMD vectors.

The scalar conversion bounds are limited to types that every floating-point element can represent losslessly, including f16 for forward-compatibility.

Self::Native selects the native-width vector for this scalar type and a SIMD backend, so a float-generic caller can use crate::dispatch!:

use fearless_simd::{dispatch, prelude::*, Level};

#[inline(always)]
fn sqrt_simd<S: Simd, T: SimdFloatElement>(simd: S, value: T) -> T {
    T::Native::<S>::splat(simd, value).sqrt()[0]
}

fn sqrt<T: SimdFloatElement>(level: Level, value: T) -> T {
    dispatch!(level, simd => sqrt_simd(simd, value))
}

let level = Level::new();
assert_eq!(sqrt(level, 4.0_f32), 2.0);
assert_eq!(sqrt(level, 4.0_f64), 2.0);

Required Associated Types§

Source

type Native<S: Simd>: SimdFloat<S, Element = Self>

The native-width floating-point vector for this scalar type and backend S.

Its lane count depends on both the scalar type and the backend, and is available as T::Native::<S>::LEN with SimdBase in scope.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl SimdFloatElement for f32

Source§

type Native<S: Simd> = <S as Simd>::f32s

Source§

impl SimdFloatElement for f64

Source§

type Native<S: Simd> = <S as Simd>::f64s

Implementors§