From fe5183e627731f076e1aee9133f71190b5b67c1a Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Fri, 23 Aug 2024 01:59:26 -0700 Subject: [PATCH 1/2] Fix the examples in cg_clif --- example/float-minmax-pass.rs | 12 ++++++------ example/std_example.rs | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/example/float-minmax-pass.rs b/example/float-minmax-pass.rs index c54574d801d..ad46e18c11c 100644 --- a/example/float-minmax-pass.rs +++ b/example/float-minmax-pass.rs @@ -9,13 +9,13 @@ #[repr(simd)] #[derive(Copy, Clone, PartialEq, Debug)] -struct f32x4(pub f32, pub f32, pub f32, pub f32); +struct f32x4(pub [f32; 4]); use std::intrinsics::simd::*; fn main() { - let x = f32x4(1.0, 2.0, 3.0, 4.0); - let y = f32x4(2.0, 1.0, 4.0, 3.0); + let x = f32x4([1.0, 2.0, 3.0, 4.0]); + let y = f32x4([2.0, 1.0, 4.0, 3.0]); #[cfg(not(any(target_arch = "mips", target_arch = "mips64")))] let nan = f32::NAN; @@ -24,13 +24,13 @@ fn main() { #[cfg(any(target_arch = "mips", target_arch = "mips64"))] let nan = f32::from_bits(f32::NAN.to_bits() - 1); - let n = f32x4(nan, nan, nan, nan); + let n = f32x4([nan, nan, nan, nan]); unsafe { let min0 = simd_fmin(x, y); let min1 = simd_fmin(y, x); assert_eq!(min0, min1); - let e = f32x4(1.0, 1.0, 3.0, 3.0); + let e = f32x4([1.0, 1.0, 3.0, 3.0]); assert_eq!(min0, e); let minn = simd_fmin(x, n); assert_eq!(minn, x); @@ -40,7 +40,7 @@ fn main() { let max0 = simd_fmax(x, y); let max1 = simd_fmax(y, x); assert_eq!(max0, max1); - let e = f32x4(2.0, 2.0, 4.0, 4.0); + let e = f32x4([2.0, 2.0, 4.0, 4.0]); assert_eq!(max0, e); let maxn = simd_fmax(x, n); assert_eq!(maxn, x); diff --git a/example/std_example.rs b/example/std_example.rs index e99763e2722..f27d4ef57e0 100644 --- a/example/std_example.rs +++ b/example/std_example.rs @@ -166,7 +166,7 @@ pub fn new() -> Box> { enum Never {} } - foo(I64X2(0, 0)); + foo(I64X2([0, 0])); transmute_fat_pointer(); @@ -204,7 +204,7 @@ fn rust_call_abi() { } #[repr(simd)] -struct I64X2(i64, i64); +struct I64X2([i64; 2]); #[allow(improper_ctypes_definitions)] extern "C" fn foo(_a: I64X2) {} From 15848f3f0863fd8c4b5fb740853d961e118ba74c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 12 Sep 2024 11:33:13 +0200 Subject: [PATCH 2/2] simd_shuffle: require index argument to be a vector --- src/intrinsics/simd.rs | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index 604a88393fd..a5621aec244 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -180,34 +180,20 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>( return; } - // Make sure this is actually an array, since typeck only checks the length-suffixed - // version of this intrinsic. + // Make sure this is actually a SIMD vector. let idx_ty = fx.monomorphize(idx.node.ty(fx.mir, fx.tcx)); - let n: u16 = match idx_ty.kind() { - ty::Array(ty, len) if matches!(ty.kind(), ty::Uint(ty::UintTy::U32)) => len - .try_eval_target_usize(fx.tcx, ty::ParamEnv::reveal_all()) - .unwrap_or_else(|| { - span_bug!(span, "could not evaluate shuffle index array length") - }) - .try_into() - .unwrap(), - _ if idx_ty.is_simd() - && matches!( - idx_ty.simd_size_and_type(fx.tcx).1.kind(), - ty::Uint(ty::UintTy::U32) - ) => - { - idx_ty.simd_size_and_type(fx.tcx).0.try_into().unwrap() - } - _ => { - fx.tcx.dcx().span_err( - span, - format!("simd_shuffle index must be an array of `u32`, got `{}`", idx_ty), - ); - // Prevent verifier error - fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); - return; - } + let n: u16 = if idx_ty.is_simd() + && matches!(idx_ty.simd_size_and_type(fx.tcx).1.kind(), ty::Uint(ty::UintTy::U32)) + { + idx_ty.simd_size_and_type(fx.tcx).0.try_into().unwrap() + } else { + fx.tcx.dcx().span_err( + span, + format!("simd_shuffle index must be a SIMD vector of `u32`, got `{}`", idx_ty), + ); + // Prevent verifier error + fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); + return; }; assert_eq!(x.layout(), y.layout());