Skip to content

Commit

Permalink
Rollup merge of #130268 - RalfJung:simd-shuffle-idx-vector, r=compile…
Browse files Browse the repository at this point in the history
…r-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/rust#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/rust#128738, see that issue for more context.
  • Loading branch information
fmease authored Sep 14, 2024
2 parents db89a0a + 6cd6ae3 commit 8e45bff
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 12 deletions.
8 changes: 1 addition & 7 deletions src/intrinsics/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,15 +664,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
let [left, right, index] = check_arg_count(args)?;
let (left, left_len) = this.project_to_simd(left)?;
let (right, right_len) = this.project_to_simd(right)?;
let (index, index_len) = this.project_to_simd(index)?;
let (dest, dest_len) = this.project_to_simd(dest)?;

// `index` is an array or a SIMD type
let (index, index_len) = match index.layout.ty.kind() {
// FIXME: remove this once `index` must always be a SIMD vector.
ty::Array(..) => (index.clone(), index.len(this)?),
_ => this.project_to_simd(index)?,
};

assert_eq!(left_len, right_len);
assert_eq!(index_len, dest_len);

Expand Down
5 changes: 0 additions & 5 deletions tests/pass/intrinsics/portable-simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,6 @@ fn simd_intrinsics() {
i32x4::from_array([10, 2, 10, 10])
);
assert_eq!(simd_shuffle_generic::<_, i32x4, { &[3, 1, 0, 2] }>(a, b), a,);
assert_eq!(simd_shuffle::<_, _, i32x4>(a, b, const { [3u32, 1, 0, 2] }), a,);
assert_eq!(
simd_shuffle::<_, _, i32x4>(a, b, const { u32x4::from_array([3u32, 1, 0, 2]) }),
a,
Expand All @@ -628,10 +627,6 @@ fn simd_intrinsics() {
simd_shuffle_generic::<_, i32x4, { &[7, 5, 4, 6] }>(a, b),
i32x4::from_array([4, 2, 1, 10]),
);
assert_eq!(
simd_shuffle::<_, _, i32x4>(a, b, const { [7u32, 5, 4, 6] }),
i32x4::from_array([4, 2, 1, 10]),
);
assert_eq!(
simd_shuffle::<_, _, i32x4>(a, b, const { u32x4::from_array([7u32, 5, 4, 6]) }),
i32x4::from_array([4, 2, 1, 10]),
Expand Down

0 comments on commit 8e45bff

Please sign in to comment.