Skip to content

Commit 96b5b7c

Browse files
authored
Rollup merge of rust-lang#130268 - RalfJung:simd-shuffle-idx-vector, r=compiler-errors
simd_shuffle: require index argument to be a vector Remove some codegen hacks by forcing the SIMD shuffle `index` argument to be a vector, which means (thanks to rust-lang#128537) that it will automatically be passed as an immediate in LLVM. The only special-casing we still have is for the extra sanity-checks we add that ensure that the indices are all in-bounds. (And the GCC backend needs to do a bunch of work since the Rust intrinsic is modeled after what LLVM expects, which seems to be quite different from what GCC expects.) Fixes rust-lang#128738, see that issue for more context.
2 parents 857ad22 + 79d937d commit 96b5b7c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

core/src/intrinsics/simd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ extern "rust-intrinsic" {
232232
///
233233
/// `T` must be a vector.
234234
///
235-
/// `U` must be a **const** array or vector of `u32`s. This means it must either refer to a named
235+
/// `U` must be a **const** vector of `u32`s. This means it must either refer to a named
236236
/// const or be given as an inline const expression (`const { ... }`).
237237
///
238238
/// `V` must be a vector with the same element type as `T` and the same length as `U`.

portable-simd/crates/core_simd/src/swizzle.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub trait Swizzle<const N: usize> {
8585
LaneCount<N>: SupportedLaneCount,
8686
LaneCount<M>: SupportedLaneCount,
8787
{
88-
// Safety: `vector` is a vector, and the index is a const array of u32.
88+
// Safety: `vector` is a vector, and the index is a const vector of u32.
8989
unsafe {
9090
core::intrinsics::simd::simd_shuffle(
9191
vector,
@@ -103,7 +103,11 @@ pub trait Swizzle<const N: usize> {
103103
output[i] = index as u32;
104104
i += 1;
105105
}
106-
output
106+
107+
// The index list needs to be returned as a vector.
108+
#[repr(simd)]
109+
struct SimdShuffleIdx<const LEN: usize>([u32; LEN]);
110+
SimdShuffleIdx(output)
107111
},
108112
)
109113
}
@@ -121,7 +125,7 @@ pub trait Swizzle<const N: usize> {
121125
LaneCount<N>: SupportedLaneCount,
122126
LaneCount<M>: SupportedLaneCount,
123127
{
124-
// Safety: `first` and `second` are vectors, and the index is a const array of u32.
128+
// Safety: `first` and `second` are vectors, and the index is a const vector of u32.
125129
unsafe {
126130
core::intrinsics::simd::simd_shuffle(
127131
first,
@@ -139,7 +143,11 @@ pub trait Swizzle<const N: usize> {
139143
output[i] = index as u32;
140144
i += 1;
141145
}
142-
output
146+
147+
// The index list needs to be returned as a vector.
148+
#[repr(simd)]
149+
struct SimdShuffleIdx<const LEN: usize>([u32; LEN]);
150+
SimdShuffleIdx(output)
143151
},
144152
)
145153
}

0 commit comments

Comments
 (0)