diff options
| author | Caleb Zulawski <caleb.zulawski@gmail.com> | 2022-11-28 09:17:02 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-28 09:17:02 -0500 |
| commit | 1547dd66f9c3c2ba9e4998f8d4885e4f7bd62c52 (patch) | |
| tree | a173eea6e87d964259b1e62d49dc497a0a038751 | |
| parent | 645ab61a16ea5c60b5cb5359dc9ae6a5c6c7eae1 (diff) | |
| parent | 54b6f6923e281ba68d13269b43faa927c6df83d5 (diff) | |
| download | rust-1547dd66f9c3c2ba9e4998f8d4885e4f7bd62c52.tar.gz rust-1547dd66f9c3c2ba9e4998f8d4885e4f7bd62c52.zip | |
Merge pull request #318 from thomcc/simd_from_slice
Avoid a scalar loop in `Simd::from_slice`
| -rw-r--r-- | crates/core_simd/src/lib.rs | 1 | ||||
| -rw-r--r-- | crates/core_simd/src/vector.rs | 11 |
2 files changed, 5 insertions, 7 deletions
diff --git a/crates/core_simd/src/lib.rs b/crates/core_simd/src/lib.rs index a6359d1e0be..927b1654f8e 100644 --- a/crates/core_simd/src/lib.rs +++ b/crates/core_simd/src/lib.rs @@ -1,5 +1,6 @@ #![no_std] #![feature( + const_ptr_read, convert_float_to_int, decl_macro, intra_doc_pointers, diff --git a/crates/core_simd/src/vector.rs b/crates/core_simd/src/vector.rs index d109087eaa6..51b0d999a81 100644 --- a/crates/core_simd/src/vector.rs +++ b/crates/core_simd/src/vector.rs @@ -174,13 +174,10 @@ where 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) + // Safety: + // - We've checked the length is sufficient. + // - `T` and `Simd<T, N>` are Copy types. + unsafe { slice.as_ptr().cast::<Self>().read_unaligned() } } /// Performs lanewise conversion of a SIMD vector's elements to another SIMD-valid type. |
