#[repr(C)]pub struct Vec8f { /* private fields */ }
Expand description
Implementations§
Source§impl Vec8f
impl Vec8f
Sourcepub fn new(
v0: f32,
v1: f32,
v2: f32,
v3: f32,
v4: f32,
v5: f32,
v6: f32,
v7: f32,
) -> Self
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()
);
Sourcepub fn join(a: Vec4f, b: Vec4f) -> Self
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));
Sourcepub unsafe fn load_ptr_aligned(addr: *const [f32; 8]) -> Self
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]) };
Sourcepub fn load(data: &[f32; 8]) -> Self
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])
);
Sourcepub fn load_checked(data: &[f32]) -> Self
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]);
Sourcepub fn load_prefix(data: &[f32]) -> Self
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]);
Sourcepub fn load_partial(data: &[f32]) -> Self
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
);
Sourcepub fn broadcast(value: f32) -> Self
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()
);
Sourcepub unsafe fn store_ptr_aligned(&self, addr: *mut [f32; 8])
pub unsafe fn store_ptr_aligned(&self, addr: *mut [f32; 8])
Sourcepub unsafe fn store_ptr_non_temporal(&self, addr: *mut [f32; 8])
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.
Sourcepub fn store_checked(&self, slice: &mut [f32])
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);
Sourcepub fn store_prefix(&self, slice: &mut [f32])
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);
Sourcepub fn store_partial(&self, slice: &mut [f32])
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
Sourcepub fn sum(self) -> f32
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);
Sourcepub fn low(self) -> Vec4f
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));
Trait Implementations§
Source§impl<T> AddAssign<T> for Vec8fwhere
Self: Add<T, Output = Self>,
impl<T> AddAssign<T> for Vec8fwhere
Self: Add<T, Output = Self>,
Source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+=
operation. Read moreSource§impl<T> DivAssign<T> for Vec8fwhere
Self: Div<T, Output = Self>,
impl<T> DivAssign<T> for Vec8fwhere
Self: Div<T, Output = Self>,
Source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/=
operation. Read moreSource§impl<T> MulAssign<T> for Vec8fwhere
Self: Mul<T, Output = Self>,
impl<T> MulAssign<T> for Vec8fwhere
Self: Mul<T, Output = Self>,
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*=
operation. Read moreSource§impl SIMDVector for Vec8f
impl SIMDVector for Vec8f
Source§const ELEMENTS: usize = 8usize
const ELEMENTS: usize = 8usize
SIMDVector
.Source§type Underlying = (Vec4f, Vec4f)
type Underlying = (Vec4f, Vec4f)
SIMDVector
.Source§type Element = f32
type Element = f32
SIMDVector
.Source§impl<T> SubAssign<T> for Vec8fwhere
Self: Sub<T, Output = Self>,
impl<T> SubAssign<T> for Vec8fwhere
Self: Sub<T, Output = Self>,
Source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
-=
operation. Read more