Skip to content

Commit

Permalink
simd_shuffle: require index argument to be a vector
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Sep 14, 2024
1 parent 34e22e8 commit 79d937d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/src/intrinsics/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ extern "rust-intrinsic" {
///
/// `T` must be a vector.
///
/// `U` must be a **const** array or vector of `u32`s. This means it must either refer to a named
/// `U` must be a **const** vector of `u32`s. This means it must either refer to a named
/// const or be given as an inline const expression (`const { ... }`).
///
/// `V` must be a vector with the same element type as `T` and the same length as `U`.
Expand Down
16 changes: 12 additions & 4 deletions portable-simd/crates/core_simd/src/swizzle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub trait Swizzle<const N: usize> {
LaneCount<N>: SupportedLaneCount,
LaneCount<M>: SupportedLaneCount,
{
// Safety: `vector` is a vector, and the index is a const array of u32.
// Safety: `vector` is a vector, and the index is a const vector of u32.
unsafe {
core::intrinsics::simd::simd_shuffle(
vector,
Expand All @@ -103,7 +103,11 @@ pub trait Swizzle<const N: usize> {
output[i] = index as u32;
i += 1;
}
output

// The index list needs to be returned as a vector.
#[repr(simd)]
struct SimdShuffleIdx<const LEN: usize>([u32; LEN]);
SimdShuffleIdx(output)
},
)
}
Expand All @@ -121,7 +125,7 @@ pub trait Swizzle<const N: usize> {
LaneCount<N>: SupportedLaneCount,
LaneCount<M>: SupportedLaneCount,
{
// Safety: `first` and `second` are vectors, and the index is a const array of u32.
// Safety: `first` and `second` are vectors, and the index is a const vector of u32.
unsafe {
core::intrinsics::simd::simd_shuffle(
first,
Expand All @@ -139,7 +143,11 @@ pub trait Swizzle<const N: usize> {
output[i] = index as u32;
i += 1;
}
output

// The index list needs to be returned as a vector.
#[repr(simd)]
struct SimdShuffleIdx<const LEN: usize>([u32; LEN]);
SimdShuffleIdx(output)
},
)
}
Expand Down

0 comments on commit 79d937d

Please sign in to comment.