Skip to content

Commit a8be7ea

Browse files
committed
Implement new simd_shuffle signature
1 parent da83c84 commit a8be7ea

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/intrinsics/simd.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,34 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
6767
_ if intrinsic.as_str().starts_with("simd_shuffle"), (c x, c y, o idx) {
6868
validate_simd_type!(fx, intrinsic, span, x.layout().ty);
6969

70-
let n: u16 = intrinsic.as_str()["simd_shuffle".len()..].parse().unwrap();
70+
// If this intrinsic is the older "simd_shuffleN" form, simply parse the integer.
71+
// If there is no suffix, use the index array length.
72+
let n: u16 = if intrinsic == sym::simd_shuffle {
73+
// Make sure this is actually an array, since typeck only checks the length-suffixed
74+
// version of this intrinsic.
75+
let idx_ty = fx.monomorphize(idx.ty(fx.mir, fx.tcx));
76+
match idx_ty.kind() {
77+
ty::Array(ty, len) if matches!(ty.kind(), ty::Uint(ty::UintTy::U32)) => {
78+
len.try_eval_usize(fx.tcx, ty::ParamEnv::reveal_all()).unwrap_or_else(|| {
79+
span_bug!(span, "could not evaluate shuffle index array length")
80+
}).try_into().unwrap()
81+
}
82+
_ => {
83+
fx.tcx.sess.span_err(
84+
span,
85+
&format!(
86+
"simd_shuffle index must be an array of `u32`, got `{}`",
87+
idx_ty,
88+
),
89+
);
90+
// Prevent verifier error
91+
crate::trap::trap_unreachable(fx, "compilation should not have succeeded");
92+
return;
93+
}
94+
}
95+
} else {
96+
intrinsic.as_str()["simd_shuffle".len()..].parse().unwrap()
97+
};
7198

7299
assert_eq!(x.layout(), y.layout());
73100
let layout = x.layout();

0 commit comments

Comments
 (0)