Trait SimdFloatElement

pub trait SimdFloatElement: SimdElement + Neg<Output = Self> + From<i8> + From<u8>

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);

Associated Types

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.

type Bits: SimdIntElement;

The scalar bit representation of this floating-point type.

Implementors