]> git.lizzy.rs Git - rust.git/commitdiff
Fix maximum SIMD lane count, and expose it to other crates. Disallow SIMD vectors...
authorCaleb Zulawski <caleb.zulawski@gmail.com>
Sat, 23 Jan 2021 21:31:43 +0000 (16:31 -0500)
committerCaleb Zulawski <caleb.zulawski@gmail.com>
Sat, 23 Jan 2021 21:33:19 +0000 (16:33 -0500)
17 files changed:
compiler/rustc_middle/src/ty/layout.rs
compiler/rustc_typeck/src/check/check.rs
src/test/ui/consts/const-eval/simd/insert_extract.rs
src/test/ui/issues/issue-17170.rs
src/test/ui/issues/issue-17170.stderr [new file with mode: 0644]
src/test/ui/issues/issue-39720.rs
src/test/ui/issues/issue-39720.stderr [new file with mode: 0644]
src/test/ui/simd-intrinsic/simd-intrinsic-generic-elements.rs
src/test/ui/simd-intrinsic/simd-intrinsic-generic-elements.stderr
src/test/ui/simd-type-generic-monomorphisation-oversized.rs
src/test/ui/simd-type-generic-monomorphisation-oversized.stderr
src/test/ui/simd-type-generic-monomorphisation-power-of-two.rs [new file with mode: 0644]
src/test/ui/simd-type-generic-monomorphisation-power-of-two.stderr [new file with mode: 0644]
src/test/ui/simd-type.rs
src/test/ui/simd-type.stderr
src/test/ui/simd/simd-intrinsic-generic-elements.rs
src/test/ui/simd/simd-size-align.rs

index c9be59ca46c28e38731001da5c4c3c513ccdff5d..aea640645fff60949ff4259bde6b4faa38e0272c 100644 (file)
@@ -165,6 +165,13 @@ fn to_int_ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
 /// - For a slice, this is the length.
 pub const FAT_PTR_EXTRA: usize = 1;
 
+/// The maximum supported number of lanes in a SIMD vector.
+///
+/// This value is selected based on backend support:
+/// * LLVM does not appear to have a vector width limit.
+/// * Cranelift stores the base-2 log of the lane count in a 4 bit integer.
+pub const MAX_SIMD_LANES: u64 = 1 << 0xF;
+
 #[derive(Copy, Clone, Debug, TyEncodable, TyDecodable)]
 pub enum LayoutError<'tcx> {
     Unknown(Ty<'tcx>),
@@ -700,10 +707,15 @@ fn layout_raw_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx Layout, LayoutError<
                 // Can't be caught in typeck if the array length is generic.
                 if e_len == 0 {
                     tcx.sess.fatal(&format!("monomorphising SIMD type `{}` of zero length", ty));
-                } else if e_len > 65536 {
+                } else if !e_len.is_power_of_two() {
                     tcx.sess.fatal(&format!(
-                        "monomorphising SIMD type `{}` of length greater than 65536",
-                        ty,
+                        "monomorphising SIMD type `{}` of non-power-of-two length",
+                        ty
+                    ));
+                } else if e_len > MAX_SIMD_LANES {
+                    tcx.sess.fatal(&format!(
+                        "monomorphising SIMD type `{}` of length greater than {}",
+                        ty, MAX_SIMD_LANES,
                     ));
                 }
 
index 8abd3a98d4b80770b59a8a40255cd9f201833143..f86bb8eb8c9dc6ce602efc282c9ed4481d46e983 100644 (file)
@@ -12,6 +12,7 @@
 use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
 use rustc_infer::infer::{RegionVariableOrigin, TyCtxtInferExt};
 use rustc_middle::ty::fold::TypeFoldable;
+use rustc_middle::ty::layout::MAX_SIMD_LANES;
 use rustc_middle::ty::subst::GenericArgKind;
 use rustc_middle::ty::util::{Discr, IntTypeExt, Representability};
 use rustc_middle::ty::{self, ParamEnv, RegionKind, ToPredicate, Ty, TyCtxt};
@@ -1108,12 +1109,22 @@ pub fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: LocalDefId) {
                 if len == 0 {
                     struct_span_err!(tcx.sess, sp, E0075, "SIMD vector cannot be empty").emit();
                     return;
-                } else if len > 65536 {
+                } else if !len.is_power_of_two() {
                     struct_span_err!(
                         tcx.sess,
                         sp,
                         E0075,
-                        "SIMD vector cannot have more than 65536 elements"
+                        "SIMD vector length must be a power of two"
+                    )
+                    .emit();
+                    return;
+                } else if len > MAX_SIMD_LANES {
+                    struct_span_err!(
+                        tcx.sess,
+                        sp,
+                        E0075,
+                        "SIMD vector cannot have more than {} elements",
+                        MAX_SIMD_LANES,
                     )
                     .emit();
                     return;
index 92231d4ced321ea9f87d0ff529ed9deedbca36b2..9e5cb0d4eb1f83156d9b10f98974661a4a7d20bd 100644 (file)
@@ -8,7 +8,7 @@
 
 #[repr(simd)] struct i8x1(i8);
 #[repr(simd)] struct u16x2(u16, u16);
-#[repr(simd)] struct f32x3(f32, f32, f32);
+#[repr(simd)] struct f32x4(f32, f32, f32, f32);
 
 extern "platform-intrinsic" {
     #[rustc_const_stable(feature = "foo", since = "1.3.37")]
@@ -39,19 +39,23 @@ fn main() {
         assert_eq!(Y1, 42);
     }
     {
-        const U: f32x3 = f32x3(13., 14., 15.);
-        const V: f32x3 = unsafe { simd_insert(U, 1_u32, 42_f32) };
+        const U: f32x4 = f32x4(13., 14., 15., 16.);
+        const V: f32x4 = unsafe { simd_insert(U, 1_u32, 42_f32) };
         const X0: f32 = V.0;
         const X1: f32 = V.1;
         const X2: f32 = V.2;
+        const X3: f32 = V.3;
         const Y0: f32 = unsafe { simd_extract(V, 0) };
         const Y1: f32 = unsafe { simd_extract(V, 1) };
         const Y2: f32 = unsafe { simd_extract(V, 2) };
+        const Y3: f32 = unsafe { simd_extract(V, 3) };
         assert_eq!(X0, 13.);
         assert_eq!(X1, 42.);
         assert_eq!(X2, 15.);
+        assert_eq!(X3, 16.);
         assert_eq!(Y0, 13.);
         assert_eq!(Y1, 42.);
         assert_eq!(Y2, 15.);
+        assert_eq!(Y3, 16.);
     }
 }
index 8d70dacdc90104a7aa180e2fd7cce7038e10e003..49cfbab9a3e6fdd42411d0683085e4b60d7d4473 100644 (file)
@@ -1,8 +1,8 @@
-// run-pass
 #![feature(repr_simd)]
 
 #[repr(simd)]
 struct T(f64, f64, f64);
+//~^ ERROR SIMD vector length must be a power of two
 
 static X: T = T(0.0, 0.0, 0.0);
 
diff --git a/src/test/ui/issues/issue-17170.stderr b/src/test/ui/issues/issue-17170.stderr
new file mode 100644 (file)
index 0000000..b35c3c4
--- /dev/null
@@ -0,0 +1,11 @@
+error[E0075]: SIMD vector length must be a power of two
+  --> $DIR/issue-17170.rs:4:1
+   |
+LL | struct T(f64, f64, f64);
+   | ^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: monomorphising SIMD type `T` of non-power-of-two length
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0075`.
index 8cf841f9371215a254302992dcdbd3984431fb0c..7d5969265121caa0cf8c6ff6b2086f9d0a8a7ce9 100644 (file)
@@ -1,4 +1,3 @@
-// run-pass
 // ignore-emscripten FIXME(#45351)
 
 #![feature(repr_simd, platform_intrinsics)]
@@ -6,10 +5,12 @@
 #[repr(simd)]
 #[derive(Copy, Clone, Debug)]
 pub struct Char3(pub i8, pub i8, pub i8);
+//~^ ERROR SIMD vector length must be a power of two
 
 #[repr(simd)]
 #[derive(Copy, Clone, Debug)]
 pub struct Short3(pub i16, pub i16, pub i16);
+//~^ ERROR SIMD vector length must be a power of two
 
 extern "platform-intrinsic" {
     fn simd_cast<T, U>(x: T) -> U;
diff --git a/src/test/ui/issues/issue-39720.stderr b/src/test/ui/issues/issue-39720.stderr
new file mode 100644 (file)
index 0000000..355ceff
--- /dev/null
@@ -0,0 +1,15 @@
+error[E0075]: SIMD vector length must be a power of two
+  --> $DIR/issue-39720.rs:7:1
+   |
+LL | pub struct Char3(pub i8, pub i8, pub i8);
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error[E0075]: SIMD vector length must be a power of two
+  --> $DIR/issue-39720.rs:12:1
+   |
+LL | pub struct Short3(pub i16, pub i16, pub i16);
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0075`.
index 5929d05f4de3169d4255f9cfd5c949ba75b5e274..493cd7a477c7a861686519145ecb0355b2a320fd 100644 (file)
@@ -9,10 +9,6 @@
 #[repr(simd)]
 #[derive(Copy, Clone)]
 #[allow(non_camel_case_types)]
-struct i32x3(i32, i32, i32);
-#[repr(simd)]
-#[derive(Copy, Clone)]
-#[allow(non_camel_case_types)]
 struct i32x4(i32, i32, i32, i32);
 #[repr(simd)]
 #[derive(Copy, Clone)]
@@ -27,10 +23,6 @@ struct i32x8(i32, i32, i32, i32,
 #[repr(simd)]
 #[derive(Copy, Clone)]
 #[allow(non_camel_case_types)]
-struct f32x3(f32, f32, f32);
-#[repr(simd)]
-#[derive(Copy, Clone)]
-#[allow(non_camel_case_types)]
 struct f32x4(f32, f32, f32, f32);
 #[repr(simd)]
 #[derive(Copy, Clone)]
@@ -43,7 +35,6 @@ struct f32x8(f32, f32, f32, f32,
     fn simd_extract<T, E>(x: T, idx: u32) -> E;
 
     fn simd_shuffle2<T, U>(x: T, y: T, idx: [u32; 2]) -> U;
-    fn simd_shuffle3<T, U>(x: T, y: T, idx: [u32; 3]) -> U;
     fn simd_shuffle4<T, U>(x: T, y: T, idx: [u32; 4]) -> U;
     fn simd_shuffle8<T, U>(x: T, y: T, idx: [u32; 8]) -> U;
 }
@@ -61,8 +52,6 @@ fn main() {
 
         simd_shuffle2::<i32, i32>(0, 0, [0; 2]);
         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
-        simd_shuffle3::<i32, i32>(0, 0, [0; 3]);
-        //~^ ERROR expected SIMD input type, found non-SIMD `i32`
         simd_shuffle4::<i32, i32>(0, 0, [0; 4]);
         //~^ ERROR expected SIMD input type, found non-SIMD `i32`
         simd_shuffle8::<i32, i32>(0, 0, [0; 8]);
@@ -70,8 +59,6 @@ fn main() {
 
         simd_shuffle2::<_, f32x2>(x, x, [0; 2]);
 //~^ ERROR element type `i32` (element of input `i32x4`), found `f32x2` with element type `f32`
-        simd_shuffle3::<_, f32x3>(x, x, [0; 3]);
-//~^ ERROR element type `i32` (element of input `i32x4`), found `f32x3` with element type `f32`
         simd_shuffle4::<_, f32x4>(x, x, [0; 4]);
 //~^ ERROR element type `i32` (element of input `i32x4`), found `f32x4` with element type `f32`
         simd_shuffle8::<_, f32x8>(x, x, [0; 8]);
@@ -79,10 +66,8 @@ fn main() {
 
         simd_shuffle2::<_, i32x8>(x, x, [0; 2]);
         //~^ ERROR expected return type of length 2, found `i32x8` with length 8
-        simd_shuffle3::<_, i32x4>(x, x, [0; 3]);
-        //~^ ERROR expected return type of length 3, found `i32x4` with length 4
-        simd_shuffle4::<_, i32x3>(x, x, [0; 4]);
-        //~^ ERROR expected return type of length 4, found `i32x3` with length 3
+        simd_shuffle4::<_, i32x8>(x, x, [0; 4]);
+        //~^ ERROR expected return type of length 4, found `i32x8` with length 8
         simd_shuffle8::<_, i32x2>(x, x, [0; 8]);
         //~^ ERROR expected return type of length 8, found `i32x2` with length 2
     }
index 78022c0c8bd98c321f80043f9f6be99465d93fc5..703e64d1ddcc83c31a952cc5203a263ca114cb86 100644 (file)
@@ -1,93 +1,75 @@
 error[E0511]: invalid monomorphization of `simd_insert` intrinsic: expected SIMD input type, found non-SIMD `i32`
-  --> $DIR/simd-intrinsic-generic-elements.rs:55:9
+  --> $DIR/simd-intrinsic-generic-elements.rs:46:9
    |
 LL |         simd_insert(0, 0, 0);
    |         ^^^^^^^^^^^^^^^^^^^^
 
 error[E0511]: invalid monomorphization of `simd_insert` intrinsic: expected inserted type `i32` (element of input `i32x4`), found `f64`
-  --> $DIR/simd-intrinsic-generic-elements.rs:57:9
+  --> $DIR/simd-intrinsic-generic-elements.rs:48:9
    |
 LL |         simd_insert(x, 0, 1.0);
    |         ^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0511]: invalid monomorphization of `simd_extract` intrinsic: expected return type `i32` (element of input `i32x4`), found `f32`
-  --> $DIR/simd-intrinsic-generic-elements.rs:59:9
+  --> $DIR/simd-intrinsic-generic-elements.rs:50:9
    |
 LL |         simd_extract::<_, f32>(x, 0);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0511]: invalid monomorphization of `simd_shuffle2` intrinsic: expected SIMD input type, found non-SIMD `i32`
-  --> $DIR/simd-intrinsic-generic-elements.rs:62:9
+  --> $DIR/simd-intrinsic-generic-elements.rs:53:9
    |
 LL |         simd_shuffle2::<i32, i32>(0, 0, [0; 2]);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error[E0511]: invalid monomorphization of `simd_shuffle3` intrinsic: expected SIMD input type, found non-SIMD `i32`
-  --> $DIR/simd-intrinsic-generic-elements.rs:64:9
-   |
-LL |         simd_shuffle3::<i32, i32>(0, 0, [0; 3]);
-   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
 error[E0511]: invalid monomorphization of `simd_shuffle4` intrinsic: expected SIMD input type, found non-SIMD `i32`
-  --> $DIR/simd-intrinsic-generic-elements.rs:66:9
+  --> $DIR/simd-intrinsic-generic-elements.rs:55:9
    |
 LL |         simd_shuffle4::<i32, i32>(0, 0, [0; 4]);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0511]: invalid monomorphization of `simd_shuffle8` intrinsic: expected SIMD input type, found non-SIMD `i32`
-  --> $DIR/simd-intrinsic-generic-elements.rs:68:9
+  --> $DIR/simd-intrinsic-generic-elements.rs:57:9
    |
 LL |         simd_shuffle8::<i32, i32>(0, 0, [0; 8]);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0511]: invalid monomorphization of `simd_shuffle2` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x2` with element type `f32`
-  --> $DIR/simd-intrinsic-generic-elements.rs:71:9
+  --> $DIR/simd-intrinsic-generic-elements.rs:60:9
    |
 LL |         simd_shuffle2::<_, f32x2>(x, x, [0; 2]);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error[E0511]: invalid monomorphization of `simd_shuffle3` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x3` with element type `f32`
-  --> $DIR/simd-intrinsic-generic-elements.rs:73:9
-   |
-LL |         simd_shuffle3::<_, f32x3>(x, x, [0; 3]);
-   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
 error[E0511]: invalid monomorphization of `simd_shuffle4` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x4` with element type `f32`
-  --> $DIR/simd-intrinsic-generic-elements.rs:75:9
+  --> $DIR/simd-intrinsic-generic-elements.rs:62:9
    |
 LL |         simd_shuffle4::<_, f32x4>(x, x, [0; 4]);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0511]: invalid monomorphization of `simd_shuffle8` intrinsic: expected return element type `i32` (element of input `i32x4`), found `f32x8` with element type `f32`
-  --> $DIR/simd-intrinsic-generic-elements.rs:77:9
+  --> $DIR/simd-intrinsic-generic-elements.rs:64:9
    |
 LL |         simd_shuffle8::<_, f32x8>(x, x, [0; 8]);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0511]: invalid monomorphization of `simd_shuffle2` intrinsic: expected return type of length 2, found `i32x8` with length 8
-  --> $DIR/simd-intrinsic-generic-elements.rs:80:9
+  --> $DIR/simd-intrinsic-generic-elements.rs:67:9
    |
 LL |         simd_shuffle2::<_, i32x8>(x, x, [0; 2]);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error[E0511]: invalid monomorphization of `simd_shuffle3` intrinsic: expected return type of length 3, found `i32x4` with length 4
-  --> $DIR/simd-intrinsic-generic-elements.rs:82:9
+error[E0511]: invalid monomorphization of `simd_shuffle4` intrinsic: expected return type of length 4, found `i32x8` with length 8
+  --> $DIR/simd-intrinsic-generic-elements.rs:69:9
    |
-LL |         simd_shuffle3::<_, i32x4>(x, x, [0; 3]);
-   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error[E0511]: invalid monomorphization of `simd_shuffle4` intrinsic: expected return type of length 4, found `i32x3` with length 3
-  --> $DIR/simd-intrinsic-generic-elements.rs:84:9
-   |
-LL |         simd_shuffle4::<_, i32x3>(x, x, [0; 4]);
+LL |         simd_shuffle4::<_, i32x8>(x, x, [0; 4]);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0511]: invalid monomorphization of `simd_shuffle8` intrinsic: expected return type of length 8, found `i32x2` with length 2
-  --> $DIR/simd-intrinsic-generic-elements.rs:86:9
+  --> $DIR/simd-intrinsic-generic-elements.rs:71:9
    |
 LL |         simd_shuffle8::<_, i32x2>(x, x, [0; 8]);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: aborting due to 15 previous errors
+error: aborting due to 12 previous errors
 
 For more information about this error, try `rustc --explain E0511`.
index 48bf8345db9776a1bd5cb68f30bd955aafe994ae..bd0d457b35e2763ef03dbdc5bf089f57979d7551 100644 (file)
@@ -2,11 +2,11 @@
 
 #![feature(repr_simd, platform_intrinsics)]
 
-// error-pattern:monomorphising SIMD type `Simd<65537_usize>` of length greater than 65536
+// error-pattern:monomorphising SIMD type `Simd<65536_usize>` of length greater than 32768
 
 #[repr(simd)]
 struct Simd<const N: usize>([f32; N]);
 
 fn main() {
-    let _ = Simd::<65537>([0.; 65537]);
+    let _ = Simd::<65536>([0.; 65536]);
 }
index c8dab7bfbe88346ccc4227d2d7d17bd9c93374c6..f4418350115321c9e8be87b778251e4ed363ef6a 100644 (file)
@@ -1,4 +1,4 @@
-error: monomorphising SIMD type `Simd<65537_usize>` of length greater than 65536
+error: monomorphising SIMD type `Simd<65536_usize>` of length greater than 32768
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/simd-type-generic-monomorphisation-power-of-two.rs b/src/test/ui/simd-type-generic-monomorphisation-power-of-two.rs
new file mode 100644 (file)
index 0000000..3a0b9e0
--- /dev/null
@@ -0,0 +1,12 @@
+// build-fail
+
+#![feature(repr_simd, platform_intrinsics)]
+
+// error-pattern:monomorphising SIMD type `Simd<3_usize>` of non-power-of-two length
+
+#[repr(simd)]
+struct Simd<const N: usize>([f32; N]);
+
+fn main() {
+    let _ = Simd::<3>([0.; 3]);
+}
diff --git a/src/test/ui/simd-type-generic-monomorphisation-power-of-two.stderr b/src/test/ui/simd-type-generic-monomorphisation-power-of-two.stderr
new file mode 100644 (file)
index 0000000..82cc0d8
--- /dev/null
@@ -0,0 +1,4 @@
+error: monomorphising SIMD type `Simd<3_usize>` of non-power-of-two length
+
+error: aborting due to previous error
+
index 269715d5e8ed0417d0839b12c17af75a24b92c89..87df26434d7d303f6aa9613e6be91516c2b97d77 100644 (file)
@@ -9,6 +9,9 @@
 #[repr(simd)]
 struct empty2([f32; 0]); //~ ERROR SIMD vector cannot be empty
 
+#[repr(simd)]
+struct pow2([f32; 7]); //~ ERROR SIMD vector length must be a power of two
+
 #[repr(simd)]
 struct i64f64(i64, f64); //~ ERROR SIMD vector should be homogeneous
 
@@ -21,9 +24,9 @@
 struct FooV2([Foo; 2]); //~ ERROR SIMD vector element type should be a primitive scalar (integer/float/pointer) type
 
 #[repr(simd)]
-struct TooBig([f32; 65537]); //~ ERROR SIMD vector cannot have more than 65536 elements
+struct TooBig([f32; 65536]); //~ ERROR SIMD vector cannot have more than 32768 elements
 
 #[repr(simd)]
-struct JustRight([u128; 65536]);
+struct JustRight([u128; 32768]);
 
 fn main() {}
index 5fe12c9822769b376f9e17a83343d9619f654bee..8b15ef05e032b4f461e81d0f0e1d89f7ea583ce4 100644 (file)
@@ -10,31 +10,37 @@ error[E0075]: SIMD vector cannot be empty
 LL | struct empty2([f32; 0]);
    | ^^^^^^^^^^^^^^^^^^^^^^^^
 
-error[E0076]: SIMD vector should be homogeneous
+error[E0075]: SIMD vector length must be a power of two
   --> $DIR/simd-type.rs:13:1
    |
+LL | struct pow2([f32; 7]);
+   | ^^^^^^^^^^^^^^^^^^^^^^
+
+error[E0076]: SIMD vector should be homogeneous
+  --> $DIR/simd-type.rs:16:1
+   |
 LL | struct i64f64(i64, f64);
    | ^^^^^^^^^^^^^^^^^^^^^^^^ SIMD elements must have the same type
 
 error[E0077]: SIMD vector element type should be a primitive scalar (integer/float/pointer) type
-  --> $DIR/simd-type.rs:18:1
+  --> $DIR/simd-type.rs:21:1
    |
 LL | struct FooV(Foo, Foo);
    | ^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0077]: SIMD vector element type should be a primitive scalar (integer/float/pointer) type
-  --> $DIR/simd-type.rs:21:1
+  --> $DIR/simd-type.rs:24:1
    |
 LL | struct FooV2([Foo; 2]);
    | ^^^^^^^^^^^^^^^^^^^^^^^
 
-error[E0075]: SIMD vector cannot have more than 65536 elements
-  --> $DIR/simd-type.rs:24:1
+error[E0075]: SIMD vector cannot have more than 32768 elements
+  --> $DIR/simd-type.rs:27:1
    |
-LL | struct TooBig([f32; 65537]);
+LL | struct TooBig([f32; 65536]);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: aborting due to 6 previous errors
+error: aborting due to 7 previous errors
 
 Some errors have detailed explanations: E0075, E0076, E0077.
 For more information about an error, try `rustc --explain E0075`.
index ea3d4b1894416eba4df1e0f84d2e26c1b41c3954..a85ec7c58235ba8554c7ab750a4def27c2f9dd4e 100644 (file)
 #[repr(simd)]
 #[derive(Copy, Clone, Debug, PartialEq)]
 #[allow(non_camel_case_types)]
-struct i32x3(i32, i32, i32);
-#[repr(simd)]
-#[derive(Copy, Clone, Debug, PartialEq)]
-#[allow(non_camel_case_types)]
 struct i32x4(i32, i32, i32, i32);
 #[repr(simd)]
 #[derive(Copy, Clone, Debug, PartialEq)]
@@ -26,7 +22,6 @@ struct i32x8(i32, i32, i32, i32,
     fn simd_extract<T, E>(x: T, idx: u32) -> E;
 
     fn simd_shuffle2<T, U>(x: T, y: T, idx: [u32; 2]) -> U;
-    fn simd_shuffle3<T, U>(x: T, y: T, idx: [u32; 3]) -> U;
     fn simd_shuffle4<T, U>(x: T, y: T, idx: [u32; 4]) -> U;
     fn simd_shuffle8<T, U>(x: T, y: T, idx: [u32; 8]) -> U;
 }
@@ -45,17 +40,12 @@ macro_rules! all_eq {
 
 fn main() {
     let x2 = i32x2(20, 21);
-    let x3 = i32x3(30, 31, 32);
     let x4 = i32x4(40, 41, 42, 43);
     let x8 = i32x8(80, 81, 82, 83, 84, 85, 86, 87);
     unsafe {
         all_eq!(simd_insert(x2, 0, 100), i32x2(100, 21));
         all_eq!(simd_insert(x2, 1, 100), i32x2(20, 100));
 
-        all_eq!(simd_insert(x3, 0, 100), i32x3(100, 31, 32));
-        all_eq!(simd_insert(x3, 1, 100), i32x3(30, 100, 32));
-        all_eq!(simd_insert(x3, 2, 100), i32x3(30, 31, 100));
-
         all_eq!(simd_insert(x4, 0, 100), i32x4(100, 41, 42, 43));
         all_eq!(simd_insert(x4, 1, 100), i32x4(40, 100, 42, 43));
         all_eq!(simd_insert(x4, 2, 100), i32x4(40, 41, 100, 43));
@@ -73,10 +63,6 @@ fn main() {
         all_eq!(simd_extract(x2, 0), 20);
         all_eq!(simd_extract(x2, 1), 21);
 
-        all_eq!(simd_extract(x3, 0), 30);
-        all_eq!(simd_extract(x3, 1), 31);
-        all_eq!(simd_extract(x3, 2), 32);
-
         all_eq!(simd_extract(x4, 0), 40);
         all_eq!(simd_extract(x4, 1), 41);
         all_eq!(simd_extract(x4, 2), 42);
@@ -93,30 +79,20 @@ fn main() {
     }
 
     let y2 = i32x2(120, 121);
-    let y3 = i32x3(130, 131, 132);
     let y4 = i32x4(140, 141, 142, 143);
     let y8 = i32x8(180, 181, 182, 183, 184, 185, 186, 187);
     unsafe {
         all_eq!(simd_shuffle2(x2, y2, [3, 0]), i32x2(121, 20));
-        all_eq!(simd_shuffle3(x2, y2, [3, 0, 1]), i32x3(121, 20, 21));
         all_eq!(simd_shuffle4(x2, y2, [3, 0, 1, 2]), i32x4(121, 20, 21, 120));
         all_eq!(simd_shuffle8(x2, y2, [3, 0, 1, 2, 1, 2, 3, 0]),
                 i32x8(121, 20, 21, 120, 21, 120, 121, 20));
 
-        all_eq!(simd_shuffle2(x3, y3, [4, 2]), i32x2(131, 32));
-        all_eq!(simd_shuffle3(x3, y3, [4, 2, 3]), i32x3(131, 32, 130));
-        all_eq!(simd_shuffle4(x3, y3, [4, 2, 3, 0]), i32x4(131, 32, 130, 30));
-        all_eq!(simd_shuffle8(x3, y3, [4, 2, 3, 0, 1, 5, 5, 1]),
-                i32x8(131, 32, 130, 30, 31, 132, 132, 31));
-
         all_eq!(simd_shuffle2(x4, y4, [7, 2]), i32x2(143, 42));
-        all_eq!(simd_shuffle3(x4, y4, [7, 2, 5]), i32x3(143, 42, 141));
         all_eq!(simd_shuffle4(x4, y4, [7, 2, 5, 0]), i32x4(143, 42, 141, 40));
         all_eq!(simd_shuffle8(x4, y4, [7, 2, 5, 0, 3, 6, 4, 1]),
                 i32x8(143, 42, 141, 40, 43, 142, 140, 41));
 
         all_eq!(simd_shuffle2(x8, y8, [11, 5]), i32x2(183, 85));
-        all_eq!(simd_shuffle3(x8, y8, [11, 5, 15]), i32x3(183, 85, 187));
         all_eq!(simd_shuffle4(x8, y8, [11, 5, 15, 0]), i32x4(183, 85, 187, 80));
         all_eq!(simd_shuffle8(x8, y8, [11, 5, 15, 0, 3, 8, 12, 1]),
                 i32x8(183, 85, 187, 80, 83, 180, 184, 81));
index 556013788c33557c0b81445d0b3d5d235d1dd5a5..0afa4947225d3b719a0b92bd3fcf6d9280fccf48 100644 (file)
 /// `T` should satisfy `size_of T (mod min_align_of T) === 0` to be stored at `Vec<T>` properly
 /// Please consult the issue #20460
 fn check<T>() {
-    assert_eq!(mem::size_of::<T>() % mem::min_align_of::<T>(), 0)
+    assert_eq!(mem::size_of::<T>() % mem::min_align_of::<T>(), 0);
+    assert_eq!(mem::size_of::<T>() % mem::min_align_of::<T>(), 0);
+    assert_eq!(mem::size_of::<T>() % mem::min_align_of::<T>(), 0);
 }
 
-fn main() {
-    check::<u8x2>();
-    check::<u8x3>();
-    check::<u8x4>();
-    check::<u8x5>();
-    check::<u8x6>();
-    check::<u8x7>();
-    check::<u8x8>();
+#[repr(simd)]
+struct U8<const N: usize>([u8; N]);
 
-    check::<i16x2>();
-    check::<i16x3>();
-    check::<i16x4>();
-    check::<i16x5>();
-    check::<i16x6>();
-    check::<i16x7>();
-    check::<i16x8>();
+#[repr(simd)]
+struct I16<const N: usize>([i16; N]);
 
-    check::<f32x2>();
-    check::<f32x3>();
-    check::<f32x4>();
-    check::<f32x5>();
-    check::<f32x6>();
-    check::<f32x7>();
-    check::<f32x8>();
+#[repr(simd)]
+struct F32<const N: usize>([f32; N]);
 
-    check::<usizex2>();
-    check::<usizex3>();
-    check::<usizex4>();
-    check::<usizex5>();
-    check::<usizex6>();
-    check::<usizex7>();
-    check::<usizex8>();
+#[repr(simd)]
+struct Usize<const N: usize>([usize; N]);
 
-    check::<isizex2>();
-    check::<isizex3>();
-    check::<isizex4>();
-    check::<isizex5>();
-    check::<isizex6>();
-    check::<isizex7>();
-    check::<isizex8>();
-}
+#[repr(simd)]
+struct Isize<const N: usize>([isize; N]);
 
-#[repr(simd)] struct u8x2(u8, u8);
-#[repr(simd)] struct u8x3(u8, u8, u8);
-#[repr(simd)] struct u8x4(u8, u8, u8, u8);
-#[repr(simd)] struct u8x5(u8, u8, u8, u8, u8);
-#[repr(simd)] struct u8x6(u8, u8, u8, u8, u8, u8);
-#[repr(simd)] struct u8x7(u8, u8, u8, u8, u8, u8, u8);
-#[repr(simd)] struct u8x8(u8, u8, u8, u8, u8, u8, u8, u8);
+fn main() {
+    check::<U8<2>>();
+    check::<U8<4>>();
+    check::<U8<8>>();
 
-#[repr(simd)] struct i16x2(i16, i16);
-#[repr(simd)] struct i16x3(i16, i16, i16);
-#[repr(simd)] struct i16x4(i16, i16, i16, i16);
-#[repr(simd)] struct i16x5(i16, i16, i16, i16, i16);
-#[repr(simd)] struct i16x6(i16, i16, i16, i16, i16, i16);
-#[repr(simd)] struct i16x7(i16, i16, i16, i16, i16, i16, i16);
-#[repr(simd)] struct i16x8(i16, i16, i16, i16, i16, i16, i16, i16);
+    check::<I16<2>>();
+    check::<I16<4>>();
+    check::<I16<8>>();
 
-#[repr(simd)] struct f32x2(f32, f32);
-#[repr(simd)] struct f32x3(f32, f32, f32);
-#[repr(simd)] struct f32x4(f32, f32, f32, f32);
-#[repr(simd)] struct f32x5(f32, f32, f32, f32, f32);
-#[repr(simd)] struct f32x6(f32, f32, f32, f32, f32, f32);
-#[repr(simd)] struct f32x7(f32, f32, f32, f32, f32, f32, f32);
-#[repr(simd)] struct f32x8(f32, f32, f32, f32, f32, f32, f32, f32);
+    check::<F32<2>>();
+    check::<F32<4>>();
+    check::<F32<8>>();
 
-#[repr(simd)] struct usizex2(usize, usize);
-#[repr(simd)] struct usizex3(usize, usize, usize);
-#[repr(simd)] struct usizex4(usize, usize, usize, usize);
-#[repr(simd)] struct usizex5(usize, usize, usize, usize, usize);
-#[repr(simd)] struct usizex6(usize, usize, usize, usize, usize, usize);
-#[repr(simd)] struct usizex7(usize, usize, usize, usize, usize, usize, usize);
-#[repr(simd)] struct usizex8(usize, usize, usize, usize, usize, usize, usize, usize);
+    check::<Usize<2>>();
+    check::<Usize<4>>();
+    check::<Usize<8>>();
 
-#[repr(simd)] struct isizex2(isize, isize);
-#[repr(simd)] struct isizex3(isize, isize, isize);
-#[repr(simd)] struct isizex4(isize, isize, isize, isize);
-#[repr(simd)] struct isizex5(isize, isize, isize, isize, isize);
-#[repr(simd)] struct isizex6(isize, isize, isize, isize, isize, isize);
-#[repr(simd)] struct isizex7(isize, isize, isize, isize, isize, isize, isize);
-#[repr(simd)] struct isizex8(isize, isize, isize, isize, isize, isize, isize, isize);
+    check::<Isize<2>>();
+    check::<Isize<4>>();
+    check::<Isize<8>>();
+}