Skip to content

Commit 7555cbb

Browse files
committed
Auto merge of #3097 - RalfJung:rustup, r=RalfJung
Rustup
2 parents 574f234 + 06064e7 commit 7555cbb

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2ba4eb2d49e774b5fbc2a06258ac7b0f60b92b7e
1+
bb6c66be3793ac5c738eeac91ecdc4b99388d0b4

src/shims/intrinsics/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
6060
}
6161

6262
// The rest jumps to `ret` immediately.
63-
this.emulate_intrinsic_by_name(intrinsic_name, args, dest)?;
63+
this.emulate_intrinsic_by_name(intrinsic_name, instance.args, args, dest)?;
6464

6565
trace!("{:?}", this.dump_place(dest));
6666
this.go_to_block(ret);
@@ -71,6 +71,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
7171
fn emulate_intrinsic_by_name(
7272
&mut self,
7373
intrinsic_name: &str,
74+
generic_args: ty::GenericArgsRef<'tcx>,
7475
args: &[OpTy<'tcx, Provenance>],
7576
dest: &PlaceTy<'tcx, Provenance>,
7677
) -> InterpResult<'tcx> {
@@ -80,7 +81,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
8081
return this.emulate_atomic_intrinsic(name, args, dest);
8182
}
8283
if let Some(name) = intrinsic_name.strip_prefix("simd_") {
83-
return this.emulate_simd_intrinsic(name, args, dest);
84+
return this.emulate_simd_intrinsic(name, generic_args, args, dest);
8485
}
8586

8687
match intrinsic_name {

src/shims/intrinsics/simd.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
1212
fn emulate_simd_intrinsic(
1313
&mut self,
1414
intrinsic_name: &str,
15+
generic_args: ty::GenericArgsRef<'tcx>,
1516
args: &[OpTy<'tcx, Provenance>],
1617
dest: &PlaceTy<'tcx, Provenance>,
1718
) -> InterpResult<'tcx> {
@@ -488,6 +489,44 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
488489
this.write_immediate(*val, &dest)?;
489490
}
490491
}
492+
"shuffle_generic" => {
493+
let [left, right] = check_arg_count(args)?;
494+
let (left, left_len) = this.operand_to_simd(left)?;
495+
let (right, right_len) = this.operand_to_simd(right)?;
496+
let (dest, dest_len) = this.place_to_simd(dest)?;
497+
498+
let index = generic_args[2]
499+
.expect_const()
500+
.eval(*this.tcx, this.param_env(), Some(this.tcx.span))
501+
.unwrap()
502+
.unwrap_branch();
503+
let index_len = index.len();
504+
505+
assert_eq!(left_len, right_len);
506+
assert_eq!(index_len as u64, dest_len);
507+
508+
for i in 0..dest_len {
509+
let src_index: u64 = index[usize::try_from(i).unwrap()]
510+
.unwrap_leaf()
511+
.try_to_u32()
512+
.unwrap()
513+
.into();
514+
let dest = this.project_index(&dest, i)?;
515+
516+
let val = if src_index < left_len {
517+
this.read_immediate(&this.project_index(&left, src_index)?)?
518+
} else if src_index < left_len.checked_add(right_len).unwrap() {
519+
let right_idx = src_index.checked_sub(left_len).unwrap();
520+
this.read_immediate(&this.project_index(&right, right_idx)?)?
521+
} else {
522+
span_bug!(
523+
this.cur_span(),
524+
"simd_shuffle index {src_index} is out of bounds for 2 vectors of size {left_len}",
525+
);
526+
};
527+
this.write_immediate(*val, &dest)?;
528+
}
529+
}
491530
"shuffle" => {
492531
let [left, right, index] = check_arg_count(args)?;
493532
let (left, left_len) = this.operand_to_simd(left)?;

tests/pass/portable-simd.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//@compile-flags: -Zmiri-strict-provenance
2-
#![feature(portable_simd, platform_intrinsics)]
2+
#![feature(portable_simd, platform_intrinsics, adt_const_params, inline_const)]
3+
#![allow(incomplete_features)]
34
use std::simd::*;
45

56
extern "platform-intrinsic" {
@@ -390,6 +391,8 @@ fn simd_intrinsics() {
390391
fn simd_reduce_any<T>(x: T) -> bool;
391392
fn simd_reduce_all<T>(x: T) -> bool;
392393
fn simd_select<M, T>(m: M, yes: T, no: T) -> T;
394+
fn simd_shuffle_generic<T, U, const IDX: &'static [u32]>(x: T, y: T) -> U;
395+
fn simd_shuffle<T, IDX, U>(x: T, y: T, idx: IDX) -> U;
393396
}
394397
unsafe {
395398
// Make sure simd_eq returns all-1 for `true`
@@ -413,6 +416,16 @@ fn simd_intrinsics() {
413416
simd_select(i8x4::from_array([0, -1, -1, 0]), b, a),
414417
i32x4::from_array([10, 2, 10, 10])
415418
);
419+
assert_eq!(simd_shuffle_generic::<_, i32x4, { &[3, 1, 0, 2] }>(a, b), a,);
420+
assert_eq!(simd_shuffle::<_, _, i32x4>(a, b, const { [3, 1, 0, 2] }), a,);
421+
assert_eq!(
422+
simd_shuffle_generic::<_, i32x4, { &[7, 5, 4, 6] }>(a, b),
423+
i32x4::from_array([4, 2, 1, 10]),
424+
);
425+
assert_eq!(
426+
simd_shuffle::<_, _, i32x4>(a, b, const { [7, 5, 4, 6] }),
427+
i32x4::from_array([4, 2, 1, 10]),
428+
);
416429
}
417430
}
418431

0 commit comments

Comments
 (0)