Struct Vec8f

Source
#[repr(C)]
pub struct Vec8f { /* private fields */ }
Expand description

Represents a packed vector of 8 single-precision floating-point values.

On platforms with AVX support Vec8f is a [__m256] wrapper. Otherwise it is a pair of Vec4f values.

Implementations§

Source§

impl Vec8f

Source

pub fn new( v0: f32, v1: f32, v2: f32, v3: f32, v4: f32, v5: f32, v6: f32, v7: f32, ) -> Self

Initializes elements of returned vector with given values.

§Example
assert_eq!(
    Vec8f::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0),
    [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0].into()
);
Source

pub fn join(a: Vec4f, b: Vec4f) -> Self

Joins two Vec4f into a single Vec8f. The first four elements of returned vector are elements of a and the last four elements are elements of b.

See also split.

§Exmaple
let a = Vec4f::new(1.0, 2.0, 3.0, 4.0);
let b = Vec4f::new(5.0, 6.0, 7.0, 8.0);
let joined = Vec8f::join(a, b);
assert_eq!(a, joined.low());
assert_eq!(b, joined.high());
assert_eq!(joined.split(), (a, b));
Source

pub unsafe fn load_ptr(addr: *const [f32; 8]) -> Self

Loads vector from array pointer by addr. addr is not required to be aligned.

§Safety

addr must be a valid pointer.

§Example
let array = [42.0; 8];
let vec = unsafe { Vec8f::load_ptr(&array) };
Source

pub unsafe fn load_ptr_aligned(addr: *const [f32; 8]) -> Self

Loads vector from aligned array pointed by addr.

§Safety

Like load_ptr, requires addr to be valid. Unlike load_ptr, requires addr to be divisible by 32, i.e. to be a 32-bytes aligned address.

§Examples
#[repr(align(32))]
struct AlignedArray([f32; 8]);

let array = AlignedArray([42.0; 8]);
let vec = unsafe { Vec8f::load_ptr_aligned(&array.0) };
assert_eq!(vec, Vec8f::broadcast(42.0));

In the following example zeros is aligned as u16, i.e. 2-bytes aligned. Therefore zeros.as_ptr().byte_add(1) is an odd address and hence not divisible by 32.

let zeros = unsafe { std::mem::zeroed::<[u16; 20]>() };
unsafe { Vec8f::load_ptr_aligned(zeros.as_ptr().byte_add(1) as *const [f32; 8]) };
Source

pub fn load(data: &[f32; 8]) -> Self

Loads values of returned vector from given data.

§Exmaple
assert_eq!(
    Vec8f::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0),
    Vec8f::load(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0])
);
Source

pub fn load_checked(data: &[f32]) -> Self

Checks that data contains exactly eight elements and loads them into vector.

§Panics

Panics if data.len() isn’t 8.

§Examples
assert_eq!(
    Vec8f::load_checked(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]),
    Vec8f::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)
);
Vec8f::load_checked(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]);
Vec8f::load_checked(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]);
Source

pub fn load_prefix(data: &[f32]) -> Self

Loads the first eight element of data into vector.

§Panics

Panics if data contains less than eight elements.

§Exmaples
assert_eq!(
    Vec8f::load_prefix(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]),
    Vec8f::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)
);
Vec8f::load_prefix(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]);
Source

pub fn load_partial(data: &[f32]) -> Self

Loads first 8 elements of data if available otherwise initializes first elements of returned vector with values of data and rest elements with zeros.

§Exmaple
let values = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0];
assert_eq!(
    Vec8f::load_partial(&values),
    Vec8f::from(&values[..8].try_into().unwrap())
);
assert_eq!(
    Vec8f::load_partial(&values[..5]),
    Vec8f::new(1.0, 2.0, 3.0, 4.0, 5.0, 0.0, 0.0, 0.0)  // note zeros here
);
Source

pub fn broadcast(value: f32) -> Self

Returns vector with all its elements initialized with a given value, i.e. broadcasts value to all elements of returned vector.

§Example
assert_eq!(
    Vec8f::broadcast(42.0),
    [42.0; 8].into()
);
Source

pub unsafe fn store_ptr(&self, addr: *mut [f32; 8])

Stores vector into array at given address.

§Safety

addr must be a valid pointer.

Source

pub unsafe fn store_ptr_aligned(&self, addr: *mut [f32; 8])

Stores vector into aligned array at given address.

§Safety

Like store_ptr, requires addr to be valid. Unlike store_ptr, requires addr to be divisible by 32, i.e. to be a 32-bytes aligned address.

Source

pub unsafe fn store_ptr_non_temporal(&self, addr: *mut [f32; 8])

Stores vector into aligned array at given address in uncached memory (non-temporal store). This may be more efficient than store_ptr_aligned if it is unlikely that stored data will stay in cache until it is read again, for instance, when storing large blocks of memory.

§Safety

Has same requirements as store_ptr_aligned: addr must be valid and divisible by 32, i.e. to be a 32-bytes aligned address.

Source

pub fn store(&self, array: &mut [f32; 8])

Stores vector into given array.

Source

pub fn store_checked(&self, slice: &mut [f32])

Checkes that slice contains exactly eight elements and store elements of vector there.

§Panics

Panics if slice.len() isn’t 8.

§Examples
let mut data = [-1.0; 8];
Vec8f::default().store_checked(&mut data);
assert_eq!(data, [0.0; 8]);
let mut data = [-1.0; 7];
Vec8f::default().store_checked(&mut data);
let mut data = [-1.0; 9];
Vec8f::default().store_checked(&mut data);
Source

pub fn store_prefix(&self, slice: &mut [f32])

Stores elements of vector into the first eight elements of slice.

§Panics

Panics if slice contains less then eight elements.

§Exmaples
let mut data = [-1.0; 9];
Vec8f::broadcast(2.0).store_prefix(&mut data);
assert_eq!(data, [2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, -1.0]);
let mut data = [-1.0; 7];
Vec8f::default().store_prefix(&mut data);
Source

pub fn store_partial(&self, slice: &mut [f32])

Stores min(8, slice.len()) elements of vector into prefix of slice.

§Examples
let mut data = [0.0; 7];
Vec8f::broadcast(1.0).store_partial(&mut data);
assert_eq!(data, [1.0; 7]);
let mut data = [0.0; 9];
Vec8f::broadcast(1.0).store_partial(&mut data);
assert_eq!(data, [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0]);  // note last zero
Source

pub fn sum(self) -> f32

Calculates the sum of all elements of vector.

§Exmaple
let vec = Vec8f::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);
assert_eq!(vec.sum(), 36.0);
Source

pub fn low(self) -> Vec4f

Returns the first four elements of vector.

§Exmaple
let vec8 = Vec8f::new(1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0);
assert_eq!(vec8.low(), Vec4f::broadcast(1.0));
Source

pub fn high(self) -> Vec4f

Returns the last four elements of vector.

§Exmaple
let vec8 = Vec8f::new(1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0);
assert_eq!(vec8.high(), Vec4f::broadcast(2.0));
Source

pub fn split(self) -> (Vec4f, Vec4f)

Splits vector into low and high halfs.

See also join.

§Example
let vec = Vec8f::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);
let (low, high) = vec.split();
assert_eq!(low, vec.low());
assert_eq!(high, vec.high());
assert_eq!(Vec8f::join(low, high), vec);

Trait Implementations§

Source§

impl Add<<Vec8f as SIMDVector>::Element> for Vec8f

Source§

type Output = Vec8f

The resulting type after applying the + operator.
Source§

fn add(self, rhs: <Vec8f as SIMDVector>::Element) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Vec8f> for <Vec8f as SIMDVector>::Element

Source§

type Output = Vec8f

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add for Vec8f

Source§

type Output = Vec8f

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Vec8f) -> Vec8f

Performs the + operation. Read more
Source§

impl<T> AddAssign<T> for Vec8f
where Self: Add<T, Output = Self>,

Source§

fn add_assign(&mut self, rhs: T)

Performs the += operation. Read more
Source§

impl Clone for Vec8f

Source§

fn clone(&self) -> Vec8f

Returns a copy 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 Vec8f

Source§

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

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

impl Default for Vec8f

Source§

fn default() -> Self

Initializes all elements of returned vector with zero.

§Example
assert_eq!(Vec8f::default(), Vec8f::broadcast(0.0));
Source§

impl Div<<Vec8f as SIMDVector>::Element> for Vec8f

Source§

type Output = Vec8f

The resulting type after applying the / operator.
Source§

fn div(self, rhs: <Vec8f as SIMDVector>::Element) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Vec8f> for <Vec8f as SIMDVector>::Element

Source§

type Output = Vec8f

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Vec8f) -> Self::Output

Performs the / operation. Read more
Source§

impl Div for Vec8f

Source§

type Output = Vec8f

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Vec8f) -> Vec8f

Performs the / operation. Read more
Source§

impl<T> DivAssign<T> for Vec8f
where Self: Div<T, Output = Self>,

Source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
Source§

impl From<&[f32; 8]> for Vec8f

Source§

fn from(value: &[f32; 8]) -> Self

Does same as load.

Source§

impl From<&Vec8f> for [f32; 8]

Source§

fn from(value: &Vec8f) -> Self

Converts to this type from the input type.
Source§

impl From<[f32; 8]> for Vec8f

Source§

fn from(value: [f32; 8]) -> Self

Converts to this type from the input type.
Source§

impl From<(Vec4f, Vec4f)> for Vec8f

Source§

fn from((low, high): (Vec4f, Vec4f)) -> Self

Does same as join.

Source§

impl From<Vec8f> for [f32; 8]

Source§

fn from(value: Vec8f) -> Self

Converts to this type from the input type.
Source§

impl From<Vec8f> for (Vec4f, Vec4f)

Source§

fn from(vec: Vec8f) -> (Vec4f, Vec4f)

Does same as split.

Source§

impl Mul<<Vec8f as SIMDVector>::Element> for Vec8f

Source§

type Output = Vec8f

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: <Vec8f as SIMDVector>::Element) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Vec8f> for <Vec8f as SIMDVector>::Element

Source§

type Output = Vec8f

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec8f) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul for Vec8f

Source§

type Output = Vec8f

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec8f) -> Vec8f

Performs the * operation. Read more
Source§

impl<T> MulAssign<T> for Vec8f
where Self: Mul<T, Output = Self>,

Source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
Source§

impl Neg for Vec8f

Source§

fn neg(self) -> Self::Output

Flips sign bit of each element including non-finite ones.

Source§

type Output = Vec8f

The resulting type after applying the - operator.
Source§

impl PartialEq for Vec8f

Source§

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

Checks whether all elements of vectors are equal.

Note: when NaN is an element of one of the operands the result is always false.

§Examples
let a = Vec8f::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);
assert_eq!(a, a);
let a = Vec8f::broadcast(f32::NAN);
assert_ne!(a, a);
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 Product for Vec8f

Source§

fn product<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl SIMDVector for Vec8f

Source§

const ELEMENTS: usize = 8usize

Number of elements in SIMDVector.
Source§

type Underlying = (Vec4f, Vec4f)

Underlying intrinsic type or tuple of types implementing SIMDVector.
Source§

type Element = f32

Type of a single element of SIMDVector.
Source§

impl Sub<<Vec8f as SIMDVector>::Element> for Vec8f

Source§

type Output = Vec8f

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: <Vec8f as SIMDVector>::Element) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<Vec8f> for <Vec8f as SIMDVector>::Element

Source§

type Output = Vec8f

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Vec8f) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub for Vec8f

Source§

type Output = Vec8f

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Vec8f) -> Vec8f

Performs the - operation. Read more
Source§

impl<T> SubAssign<T> for Vec8f
where Self: Sub<T, Output = Self>,

Source§

fn sub_assign(&mut self, rhs: T)

Performs the -= operation. Read more
Source§

impl Sum for Vec8f

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Copy for Vec8f

Auto Trait Implementations§

§

impl Freeze for Vec8f

§

impl RefUnwindSafe for Vec8f

§

impl Send for Vec8f

§

impl Sync for Vec8f

§

impl Unpin for Vec8f

§

impl UnwindSafe for Vec8f

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.