Skip to content

Commit

Permalink
Merge pull request #318 from thomcc/simd_from_slice
Browse files Browse the repository at this point in the history
Avoid a scalar loop in `Simd::from_slice`
  • Loading branch information
calebzulawski authored Nov 28, 2022
2 parents 645ab61 + 54b6f69 commit 1547dd6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
1 change: 1 addition & 0 deletions crates/core_simd/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![no_std]
#![feature(
const_ptr_read,
convert_float_to_int,
decl_macro,
intra_doc_pointers,
Expand Down
11 changes: 4 additions & 7 deletions crates/core_simd/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1547dd6

Please sign in to comment.