Enum Level

Source
#[non_exhaustive]
pub enum Level { Fallback(Fallback), Sse4_2(Sse4_2), Avx2(Avx2), }
Expand description

The level enum with the specific SIMD capabilities available.

The contained values serve as a proof that the associated target feature is available.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Fallback(Fallback)

Scalar fallback level, i.e. no supported SIMD features are to be used.

This can be created with Level::fallback.

§

Sse4_2(Sse4_2)

The SSE4.2 instruction set on (32 and 64 bit) x86.

§

Avx2(Avx2)

The AVX2 and FMA instruction set on (32 and 64 bit) x86.

Implementations§

Source§

impl Level

Source

pub fn new() -> Self

Detect the available features on the current CPU, and returns the best level.

If no SIMD instruction set is available, a scalar fallback will be used instead.

This value will be passed to functions generated using simd_dispatch.

Source

pub fn as_sse4_2(self) -> Option<Sse4_2>

If this is a proof that SSE4.2 (or better) is available, access that instruction set.

This method should be preferred over matching against the Sse4_2 variant of self, because if Fearless SIMD gets support for an instruction set which is a superset of SSE4.2, this method will return a value even if that “better” instruction set is available.

This can be used in combination with the safe_wrappers feature to gain checked access to the level-specific SIMD capabilities.

Source

pub fn as_avx2(self) -> Option<Avx2>

If this is a proof that AVX2 and FMA (or better) is available, access that instruction set.

This method should be preferred over matching against the AVX2 variant of self, because if Fearless SIMD gets support for an instruction set which is a superset of AVX2, this method will return a value even if that “better” instruction set is available.

This can be used in combination with the safe_wrappers feature to gain checked access to the level-specific SIMD capabilities.

Source

pub fn fallback() -> Self

Create a scalar fallback level, which uses no SIMD instructions.

This is primarily intended for tests; most users should prefer Level::new.

Source

pub fn dispatch<W: WithSimd>(self, f: W) -> W::Output

Dispatch f to a context where the target features which this Level proves are available are enabled.

Most users of Fearless SIMD should prefer to use simd_dispatch to explicitly vectorize a function. That has a better developer experience than an implementation of WithSimd, and is less likely to miss a vectorization opportunity.

This has two use cases:

  1. To call a manually written implementation of WithSimd.
  2. To ask the compiler to auto-vectorize scalar code.

For the second case to work, the provided function must be attributed with #[inline(always)]. Note also that any calls that function makes to other functions will likely not be auto-vectorized, unless they are also #[inline(always)].

Trait Implementations§

Source§

impl Clone for Level

Source§

fn clone(&self) -> Level

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Level

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for Level

Auto Trait Implementations§

§

impl Freeze for Level

§

impl RefUnwindSafe for Level

§

impl Send for Level

§

impl Sync for Level

§

impl Unpin for Level

§

impl UnwindSafe for Level

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.