Trait vrl::SIMDBase

source ·
pub trait SIMDBase<const N: usize>
where Self: Into<Self::Underlying> + From<Self::Underlying>, Self::Element: Copy,
{ type Underlying; type Element; const N: usize = N;
Show 13 methods // Required methods fn broadcast(value: Self::Element) -> Self; unsafe fn load_ptr(addr: *const Self::Element) -> Self; unsafe fn store_ptr(self, addr: *mut Self::Element); fn sum(self) -> Self::Element; // Provided methods fn load(data: &[Self::Element; N]) -> Self { ... } fn load_checked(data: &[Self::Element]) -> Self { ... } fn load_prefix(data: &[Self::Element]) -> Self { ... } fn store(self, array: &mut [Self::Element; N]) { ... } fn store_checked(self, slice: &mut [Self::Element]) { ... } fn store_prefix(self, slice: &mut [Self::Element]) { ... } fn extract(self, index: usize) -> Self::Element { ... } fn extract_wrapping(self, index: usize) -> Self::Element { ... } fn extract_const<const INDEX: i32>(self) -> Self::Element { ... }
}
Expand description

Base trait for fixed-size vector types.

Required Associated Types§

source

type Underlying

Underlying intrinsic type or tuple of types.

source

type Element

Type of a single element of packed vector.

Provided Associated Constants§

source

const N: usize = N

Number of elements in vector.

Required Methods§

source

fn broadcast(value: Self::Element) -> Self

Initializes all values of returned vector with a given value.

§Examples
assert_eq!(
    Vec4f::broadcast(42.0),
    [42.0; 4].into()
);
§Note

Prefer using default instead of broadcast-ing zero.

source

unsafe fn load_ptr(addr: *const Self::Element) -> Self

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

§Safety

addr must be a valid pointer to an N-sized array.

§Example
let array = [42.0; 4];
let vec = unsafe { Vec4f::load_ptr(array.as_ptr()) };
source

unsafe fn store_ptr(self, addr: *mut Self::Element)

Stores vector into array at given address.

§Safety

addr must be a valid pointer.

source

fn sum(self) -> Self::Element

Calculates the sum of all elements of vector.

§Exmaples
assert_eq!(Vec4f::new(1.0, 2.0, 3.0, 4.0).sum(), 10.0);

Provided Methods§

source

fn load(data: &[Self::Element; N]) -> Self

Loads vector from a given array.

§Exmaples
assert_eq!(
    Vec4f::new(1.0, 2.0, 3.0, 4.0),
    Vec4f::load(&[1.0, 2.0, 3.0, 4.0])
);
source

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

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

§Panics

Panics if data.len() doesn’t equal N.

§Examples
assert_eq!(
    Vec4f::load_checked(&[1.0, 2.0, 3.0, 4.0]),
    Vec4f::new(1.0, 2.0, 3.0, 4.0)
);
Vec4f::load_checked(&[1.0, 2.0, 3.0]);
Vec4f::load_checked(&[1.0, 2.0, 3.0, 4.0, 5.0]);
source

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

Loads first N elements of data into vector.

§Panics

Panics if data contains less than N elements.

§Exmaples
assert_eq!(
    Vec4f::load_prefix(&[1.0, 2.0, 3.0, 4.0, 5.0]),
    Vec4f::new(1.0, 2.0, 3.0, 4.0)
);
Vec4f::load_prefix(&[1.0, 2.0, 3.0]);
source

fn store(self, array: &mut [Self::Element; N])

Stores vector into given array.

source

fn store_checked(self, slice: &mut [Self::Element])

Checks that slice contains exactly N elements and stores elements of vector there.

§Panics

Panics if slice.len() doesn’t equal N.

§Examples
let mut data = [-1.0; 4];
Vec4f::default().store_checked(&mut data);
assert_eq!(data, [0.0; 4]);
let mut data = [-1.0; 3];
Vec4f::default().store_checked(&mut data);
let mut data = [-1.0; 5];
Vec4f::default().store_checked(&mut data);
source

fn store_prefix(self, slice: &mut [Self::Element])

Stores elements of the vector into prefix of slice.

§Panics

Panics if slice.len() is less than N.

§Exmaples
let mut data = [-1.0; 5];
Vec4f::broadcast(2.0).store_prefix(&mut data);
assert_eq!(data, [2.0, 2.0, 2.0, 2.0, -1.0]);
let mut data = [-1.0; 3];
Vec4f::default().store_prefix(&mut data);
source

fn extract(self, index: usize) -> Self::Element

Extracts index-th element of the vector. Index 0 corresponds to the “most left” element.

§Panic

Panics if index is invalid, i.e. isn’t less than N.

§Examples
let vec = Vec4f::new(1.0, 2.0, 3.0, 4.0);
assert_eq!(vec.extract(2), 3.0);
Vec4f::default().extract(5);
§Note

If index is known at compile time consider using extract_const.

source

fn extract_wrapping(self, index: usize) -> Self::Element

Extracts index % N-th element of the vector. This corresponds to the original extract function from VCL.

§Examples
assert_eq!(Vec4f::new(1.0, 2.0, 3.0, 4.0).extract_wrapping(6), 3.0);
source

fn extract_const<const INDEX: i32>(self) -> Self::Element

Extracts INDEX-th element of the vector. Does same as extract with compile-time known index.

§Examples
let vec = Vec4f::new(1.0, 2.0, 3.0, 4.0);
assert_eq!(vec.extract_const::<2>(), 3.0);
Vec4f::default().extract_const::<5>();
§Note

Currently not all implementations assures that INDEX is valid at compile time.

Object Safety§

This trait is not object safe.

Implementors§