We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Simd::from_slice
1 parent 6e30c6e commit 54b6f69Copy full SHA for 54b6f69
crates/core_simd/src/lib.rs
@@ -1,5 +1,6 @@
1
#![no_std]
2
#![feature(
3
+ const_ptr_read,
4
convert_float_to_int,
5
decl_macro,
6
intra_doc_pointers,
crates/core_simd/src/vector.rs
@@ -174,13 +174,10 @@ where
174
slice.len() >= LANES,
175
"slice length must be at least the number of lanes"
176
);
177
- let mut array = [slice[0]; LANES];
178
- let mut i = 0;
179
- while i < LANES {
180
- array[i] = slice[i];
181
- i += 1;
182
- }
183
- Self(array)
+ // Safety:
+ // - We've checked the length is sufficient.
+ // - `T` and `Simd<T, N>` are Copy types.
+ unsafe { slice.as_ptr().cast::<Self>().read_unaligned() }
184
}
185
186
/// Performs lanewise conversion of a SIMD vector's elements to another SIMD-valid type.
0 commit comments