mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 09:44:08 +00:00
add Simd::from_slice
(#177)
* add `Simd::from_slice` uses a zeroed initial array and loops so that it can be const. unfortunately, parameterizing the assert with slice length needs `#![feature(const_fn_fn_ptr_basics)]` to work.
This commit is contained in:
parent
772bf2090e
commit
d2e87281fc
@ -57,6 +57,24 @@ where
|
||||
self.0
|
||||
}
|
||||
|
||||
/// Converts a slice to a SIMD vector containing `slice[..LANES]`
|
||||
/// # Panics
|
||||
/// `from_slice` will panic if the slice's `len` is less than the vector's `Simd::LANES`.
|
||||
#[must_use]
|
||||
pub const fn from_slice(slice: &[T]) -> Self {
|
||||
assert!(
|
||||
slice.len() >= LANES,
|
||||
"slice length must be at least the number of lanes"
|
||||
);
|
||||
let mut array = [slice[0]; LANES];
|
||||
let mut i = 0;
|
||||
while i < LANES {
|
||||
array[i] = slice[i];
|
||||
i += 1;
|
||||
}
|
||||
Self(array)
|
||||
}
|
||||
|
||||
/// Reads from potentially discontiguous indices in `slice` to construct a SIMD vector.
|
||||
/// If an index is out-of-bounds, the lane is instead selected from the `or` vector.
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user