Struct Simd256Integer

Source
pub struct Simd256Integer<S: Simd256Scalar, const LANES: usize> {
    pub inner: Simd256IntegerInner,
    /* private fields */
}
Expand description

This type packs integer data into a 256 bit value and attempts to use AVX family instructions if available for all operations.

If AVX is not determined to be available, this struct has a fallback implementation that will be slower, but still mathematically correct, and may attempt to use SSE family instructions if possible.

Fields§

§inner: Simd256IntegerInner

Underlying bit storage.

Implementations§

Source§

impl<S: Simd256Scalar, const LANES: usize> Simd256Integer<S, LANES>

Source

pub fn from_array(array: [S; LANES]) -> Self

Construct a Simd256Integer value from an array of scalar values.

This function will eventually be made const after https://github.com/rust-lang/rust/issues/80384 is resolved (it can’t currently since the compiler can’t/doesn’t prove that S cannot contain an unsafe cell).

Note that this function will fail at compile time if you attempt to construct a Simd256Integer with a number of LANES inconsistent with the size of the scalar type S. See below:

use x86_simd::integers::int256::Simd256Integer;
let splat = Simd256Integer::from_array([0; 50]);
Source

pub fn splat(s: S) -> Self

“splat” a given scalar across all lanes of this SIMD value.

Source

pub fn try_from_iter(iter: &mut impl Iterator<Item = S>) -> Option<Self>

Take LANES items from an Iterator into the lanes of a Simd256Integer.

If the Iterator::next ever returns None, immediately stop and return None (this means that the iterator will be partially consumed if the end of it is reached before a SIMD vector can be filled).

Source

pub const fn to_array(self) -> [S; LANES]

Turn this Simd256Integer into an array of its lanes.

Source

pub fn as_array_ref(&self) -> &[S; LANES]

Get a reference to the underlying data of this SIMD value as an array.

Source

pub const fn from_intrinsic(intrinsic: __m256i) -> Self

Wrap a given intrinsic value with this type.

To retrieve the intrinsic underlying this value (the reverse of this operation), use Simd256Integer::inner and Simd256IntegerInner::avx:

use x86_simd::integers::int256::{Simd256Integer, Simd256IntegerInner, u64x4};
 
let simd_value = u64x4::splat(0);
 
if std::is_x86_feature_detected!("avx2") {
    // SAFETY: We have confirmed that this field of the inner union is active by checking that the 
    // AVX2 CPU feature is available.
    let intrinsic = unsafe { simd_value.inner.avx };
}
Source

pub fn element_type_is<T: Simd256Scalar>() -> bool

Check if the element type of this Simd256Integer (S) matches the given type T using core::any::TypeId.

Source

pub unsafe fn avx2_vertical_add(a: Self, b: Self) -> Self

Available on (crate feature std or target feature avx2) and target feature avx2 only.

“vertically” Add two SIMD values to eachother using AVX2 instructions.

“vertical” means each lane of the resulting SIMD value contains the sum of the coresponding lanes of a and b.

§Safety

The caller must ensure that AVX2 CPU features are supported, otherwise calling this function will execute unsupoorted instructions (which is immediate undefined behaviour).

Source

pub unsafe fn avx2_vertical_saturating_add(a: Self, b: Self) -> Self

Available on (crate feature std or target feature avx2) and target feature avx2 only.

Saturating vertical SIMD add using AVX2 instructions. Saturated adds are generally slower than Self::avx2_vertical_add so use only when needed if you care about performance (if you don’t care about performance then why are you using this SIMD library anyway).

§Safety

The caller must ensure that AVX2 CPU features are supported, otherwise calling this function will execute unsupoorted instructions (which is immediate undefined behaviour).

Source

pub fn saturating_add(a: Self, b: Self) -> Self

Saturating add on two SIMD vectors backed by AVX2 operations or using fallback iterative/scalar instructions.

Source

pub unsafe fn avx2_vertical_cmp_eq(a: Self, b: Self) -> Self

Available on (crate feature std or target feature avx2) and target feature avx2 only.

Compare two SIMD vectors for equality of elements vertically. Lanes of the result are defined as so: If the elements of the coresponding lane of each of the input vectors are equal, then the output vector will have all 1 bits in that lane (e.g. an 0xFF value in the lane for u8x32 or i8x32). If not equal, then all 0 bits.

§Safety

The caller must ensure that AVX2 CPU features are supported, otherwise calling this function will execute unsupoorted instructions (which is immediate undefined behaviour).

Source

pub fn vertical_cmp_eq(a: Self, b: Self) -> Self

Compare the elements/lanes of two SIMD vectors for equality, setting each lane of the returned SIMD vector to all 1 bits if the coresponding elements of the input vectors are equal, and all 0 bits otherwise.

Source

pub unsafe fn avx2_vertical_abs(self) -> Self

Available on (crate feature std or target feature avx2) and target feature avx2 only.

Get the absolute value of each lane of this SIMD vector using AVX2 absolute value intrinsics.

§Safety

The caller must ensure that AVX2 CPU features are supported, otherwise calling this function will execute unsupoorted instructions (which is immediate undefined behaviour).

Source

pub fn abs(self) -> Self

Return a SIMD vector containing the absolute value of all of the elements of this SIMD vector.

Source

pub unsafe fn avx_load(ptr: *const __m256i) -> Self

Available on (crate feature std or target feature avx) and target feature avx only.

Load a SIMD Vector from the given pointer using AVX intrinsics.

§Safety

The caller must ensure that AVX CPU features are supported, otherwise calling this function will execute unsupoorted instructions (which is immediate undefined behaviour).

Source

pub fn load_from_slice(slice: &[S]) -> Self

Read LANES items from the beginning of the given slice into a SIMD vector.

§Panics

This function will panic if the length of the slice is less than LANES.

Source

pub fn try_load_from_slice(slice: &[S]) -> Option<Self>

Read LANES items from the beginning of the given slice into a SIMD vector. Returns None if the slice is not large enough.

Trait Implementations§

Source§

impl<S: Simd256Scalar, const LANES: usize> Add for Simd256Integer<S, LANES>

Source§

type Output = Simd256Integer<S, LANES>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<S: Clone + Simd256Scalar, const LANES: usize> Clone for Simd256Integer<S, LANES>

Source§

fn clone(&self) -> Simd256Integer<S, LANES>

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<S: Debug + Simd256Scalar, const LANES: usize> Debug for Simd256Integer<S, LANES>

Source§

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

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

impl<S: Simd256Scalar, const LANES: usize> PartialEq for Simd256Integer<S, LANES>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S: Copy + Simd256Scalar, const LANES: usize> Copy for Simd256Integer<S, LANES>

Source§

impl<S: Simd256Scalar, const LANES: usize> Eq for Simd256Integer<S, LANES>

Auto Trait Implementations§

§

impl<S, const LANES: usize> Freeze for Simd256Integer<S, LANES>

§

impl<S, const LANES: usize> RefUnwindSafe for Simd256Integer<S, LANES>
where S: RefUnwindSafe,

§

impl<S, const LANES: usize> Send for Simd256Integer<S, LANES>
where S: Send,

§

impl<S, const LANES: usize> Sync for Simd256Integer<S, LANES>
where S: Sync,

§

impl<S, const LANES: usize> Unpin for Simd256Integer<S, LANES>
where S: Unpin,

§

impl<S, const LANES: usize> UnwindSafe for Simd256Integer<S, LANES>
where S: UnwindSafe,

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> 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.