diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
commit | 9918693037dce8aa4bb6f08741b6812923486c18 (patch) | |
tree | 21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /tests/ui/simd | |
parent | Releasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff) | |
download | rustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip |
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/simd')
17 files changed, 354 insertions, 13 deletions
diff --git a/tests/ui/simd/libm_no_std_cant_float.rs b/tests/ui/simd/libm_no_std_cant_float.rs index 50ac8e208..f54a1faf4 100644 --- a/tests/ui/simd/libm_no_std_cant_float.rs +++ b/tests/ui/simd/libm_no_std_cant_float.rs @@ -2,7 +2,7 @@ #![no_std] #![feature(portable_simd)] use core::simd::f32x4; -use core::simd::SimdFloat; +use core::simd::num::SimdFloat; // For SIMD float ops, the LLIR version which is used to implement the portable // forms of them may become calls to math.h AKA libm. So, we can't guarantee diff --git a/tests/ui/simd/libm_std_can_float.rs b/tests/ui/simd/libm_std_can_float.rs index 1c520856e..78bd0c140 100644 --- a/tests/ui/simd/libm_std_can_float.rs +++ b/tests/ui/simd/libm_std_can_float.rs @@ -3,7 +3,7 @@ // This is the converse of the other libm test. #![feature(portable_simd)] use std::simd::f32x4; -use std::simd::{SimdFloat, StdFloat}; +use std::simd::{num::SimdFloat, StdFloat}; // For SIMD float ops, the LLIR version which is used to implement the portable // forms of them may become calls to math.h AKA libm. So, we can't guarantee diff --git a/tests/ui/simd/masked-load-store-build-fail.rs b/tests/ui/simd/masked-load-store-build-fail.rs new file mode 100644 index 000000000..9b79b3bd6 --- /dev/null +++ b/tests/ui/simd/masked-load-store-build-fail.rs @@ -0,0 +1,74 @@ +// build-fail +#![feature(repr_simd, platform_intrinsics)] + +extern "platform-intrinsic" { + fn simd_masked_load<M, P, T>(mask: M, pointer: P, values: T) -> T; + fn simd_masked_store<M, P, T>(mask: M, pointer: P, values: T) -> (); +} + +#[derive(Copy, Clone)] +#[repr(simd)] +struct Simd<T, const N: usize>([T; N]); + +fn main() { + unsafe { + let mut arr = [4u8, 5, 6, 7]; + let default = Simd::<u8, 4>([9; 4]); + + simd_masked_load( + Simd::<i8, 8>([-1, 0, -1, -1, 0, 0, 0, 0]), + arr.as_ptr(), + default + ); + //~^^^^^ ERROR expected third argument with length 8 (same as input type `Simd<i8, 8>`), found `Simd<u8, 4>` with length 4 + + simd_masked_load( + Simd::<i8, 4>([-1, 0, -1, -1]), + arr.as_ptr() as *const i8, + default + ); + //~^^^^^ ERROR expected element type `u8` of second argument `*const i8` to be a pointer to the element type `u8` of the first argument `Simd<u8, 4>`, found `u8` != `*_ u8` + + simd_masked_load( + Simd::<i8, 4>([-1, 0, -1, -1]), + arr.as_ptr(), + Simd::<u32, 4>([9; 4]) + ); + //~^^^^^ ERROR expected element type `u32` of second argument `*const u8` to be a pointer to the element type `u32` of the first argument `Simd<u32, 4>`, found `u32` != `*_ u32` + + simd_masked_load( + Simd::<u8, 4>([1, 0, 1, 1]), + arr.as_ptr(), + default + ); + //~^^^^^ ERROR expected element type `u8` of third argument `Simd<u8, 4>` to be a signed integer type + + simd_masked_store( + Simd([-1i8; 4]), + arr.as_ptr(), + Simd([5u32; 4]) + ); + //~^^^^^ ERROR expected element type `u32` of second argument `*const u8` to be a pointer to the element type `u32` of the first argument `Simd<u32, 4>`, found `u32` != `*mut u32` + + simd_masked_store( + Simd([-1i8; 4]), + arr.as_ptr(), + Simd([5u8; 4]) + ); + //~^^^^^ ERROR expected element type `u8` of second argument `*const u8` to be a pointer to the element type `u8` of the first argument `Simd<u8, 4>`, found `u8` != `*mut u8` + + simd_masked_store( + Simd([-1i8; 4]), + arr.as_mut_ptr(), + Simd([5u8; 2]) + ); + //~^^^^^ ERROR expected third argument with length 4 (same as input type `Simd<i8, 4>`), found `Simd<u8, 2>` with length 2 + + simd_masked_store( + Simd([1u32; 4]), + arr.as_mut_ptr(), + Simd([5u8; 4]) + ); + //~^^^^^ ERROR expected element type `u8` of third argument `Simd<u32, 4>` to be a signed integer type + } +} diff --git a/tests/ui/simd/masked-load-store-build-fail.stderr b/tests/ui/simd/masked-load-store-build-fail.stderr new file mode 100644 index 000000000..59af83fe0 --- /dev/null +++ b/tests/ui/simd/masked-load-store-build-fail.stderr @@ -0,0 +1,83 @@ +error[E0511]: invalid monomorphization of `simd_masked_load` intrinsic: expected third argument with length 8 (same as input type `Simd<i8, 8>`), found `Simd<u8, 4>` with length 4 + --> $DIR/masked-load-store-build-fail.rs:18:9 + | +LL | / simd_masked_load( +LL | | Simd::<i8, 8>([-1, 0, -1, -1, 0, 0, 0, 0]), +LL | | arr.as_ptr(), +LL | | default +LL | | ); + | |_________^ + +error[E0511]: invalid monomorphization of `simd_masked_load` intrinsic: expected element type `u8` of second argument `*const i8` to be a pointer to the element type `u8` of the first argument `Simd<u8, 4>`, found `u8` != `*_ u8` + --> $DIR/masked-load-store-build-fail.rs:25:9 + | +LL | / simd_masked_load( +LL | | Simd::<i8, 4>([-1, 0, -1, -1]), +LL | | arr.as_ptr() as *const i8, +LL | | default +LL | | ); + | |_________^ + +error[E0511]: invalid monomorphization of `simd_masked_load` intrinsic: expected element type `u32` of second argument `*const u8` to be a pointer to the element type `u32` of the first argument `Simd<u32, 4>`, found `u32` != `*_ u32` + --> $DIR/masked-load-store-build-fail.rs:32:9 + | +LL | / simd_masked_load( +LL | | Simd::<i8, 4>([-1, 0, -1, -1]), +LL | | arr.as_ptr(), +LL | | Simd::<u32, 4>([9; 4]) +LL | | ); + | |_________^ + +error[E0511]: invalid monomorphization of `simd_masked_load` intrinsic: expected element type `u8` of third argument `Simd<u8, 4>` to be a signed integer type + --> $DIR/masked-load-store-build-fail.rs:39:9 + | +LL | / simd_masked_load( +LL | | Simd::<u8, 4>([1, 0, 1, 1]), +LL | | arr.as_ptr(), +LL | | default +LL | | ); + | |_________^ + +error[E0511]: invalid monomorphization of `simd_masked_store` intrinsic: expected element type `u32` of second argument `*const u8` to be a pointer to the element type `u32` of the first argument `Simd<u32, 4>`, found `u32` != `*mut u32` + --> $DIR/masked-load-store-build-fail.rs:46:9 + | +LL | / simd_masked_store( +LL | | Simd([-1i8; 4]), +LL | | arr.as_ptr(), +LL | | Simd([5u32; 4]) +LL | | ); + | |_________^ + +error[E0511]: invalid monomorphization of `simd_masked_store` intrinsic: expected element type `u8` of second argument `*const u8` to be a pointer to the element type `u8` of the first argument `Simd<u8, 4>`, found `u8` != `*mut u8` + --> $DIR/masked-load-store-build-fail.rs:53:9 + | +LL | / simd_masked_store( +LL | | Simd([-1i8; 4]), +LL | | arr.as_ptr(), +LL | | Simd([5u8; 4]) +LL | | ); + | |_________^ + +error[E0511]: invalid monomorphization of `simd_masked_store` intrinsic: expected third argument with length 4 (same as input type `Simd<i8, 4>`), found `Simd<u8, 2>` with length 2 + --> $DIR/masked-load-store-build-fail.rs:60:9 + | +LL | / simd_masked_store( +LL | | Simd([-1i8; 4]), +LL | | arr.as_mut_ptr(), +LL | | Simd([5u8; 2]) +LL | | ); + | |_________^ + +error[E0511]: invalid monomorphization of `simd_masked_store` intrinsic: expected element type `u8` of third argument `Simd<u32, 4>` to be a signed integer type + --> $DIR/masked-load-store-build-fail.rs:67:9 + | +LL | / simd_masked_store( +LL | | Simd([1u32; 4]), +LL | | arr.as_mut_ptr(), +LL | | Simd([5u8; 4]) +LL | | ); + | |_________^ + +error: aborting due to 8 previous errors + +For more information about this error, try `rustc --explain E0511`. diff --git a/tests/ui/simd/masked-load-store-check-fail.rs b/tests/ui/simd/masked-load-store-check-fail.rs new file mode 100644 index 000000000..d4b35e211 --- /dev/null +++ b/tests/ui/simd/masked-load-store-check-fail.rs @@ -0,0 +1,32 @@ +// check-fail +#![feature(repr_simd, platform_intrinsics)] + +extern "platform-intrinsic" { + fn simd_masked_load<M, P, T>(mask: M, pointer: P, values: T) -> T; + fn simd_masked_store<M, P, T>(mask: M, pointer: P, values: T) -> (); +} + +#[derive(Copy, Clone)] +#[repr(simd)] +struct Simd<T, const N: usize>([T; N]); + +fn main() { + unsafe { + let mut arr = [4u8, 5, 6, 7]; + let default = Simd::<u8, 4>([9; 4]); + + let _x: Simd<u8, 2> = simd_masked_load( + Simd::<i8, 4>([-1, 0, -1, -1]), + arr.as_ptr(), + Simd::<u8, 4>([9; 4]) + ); + //~^^ ERROR mismatched types + + let _x: Simd<u32, 4> = simd_masked_load( + Simd::<u8, 4>([1, 0, 1, 1]), + arr.as_ptr(), + default + ); + //~^^ ERROR mismatched types + } +} diff --git a/tests/ui/simd/masked-load-store-check-fail.stderr b/tests/ui/simd/masked-load-store-check-fail.stderr new file mode 100644 index 000000000..5d205d607 --- /dev/null +++ b/tests/ui/simd/masked-load-store-check-fail.stderr @@ -0,0 +1,59 @@ +error[E0308]: mismatched types + --> $DIR/masked-load-store-check-fail.rs:21:13 + | +LL | let _x: Simd<u8, 2> = simd_masked_load( + | ---------------- arguments to this function are incorrect +... +LL | Simd::<u8, 4>([9; 4]) + | ^^^^^^^^^^^^^^^^^^^^^ expected `2`, found `4` + | + = note: expected struct `Simd<_, 2>` + found struct `Simd<_, 4>` +help: the return type of this call is `Simd<u8, 4>` due to the type of the argument passed + --> $DIR/masked-load-store-check-fail.rs:18:31 + | +LL | let _x: Simd<u8, 2> = simd_masked_load( + | _______________________________^ +LL | | Simd::<i8, 4>([-1, 0, -1, -1]), +LL | | arr.as_ptr(), +LL | | Simd::<u8, 4>([9; 4]) + | | --------------------- this argument influences the return type of `simd_masked_load` +LL | | ); + | |_________^ +note: function defined here + --> $DIR/masked-load-store-check-fail.rs:5:8 + | +LL | fn simd_masked_load<M, P, T>(mask: M, pointer: P, values: T) -> T; + | ^^^^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/masked-load-store-check-fail.rs:28:13 + | +LL | let _x: Simd<u32, 4> = simd_masked_load( + | ---------------- arguments to this function are incorrect +... +LL | default + | ^^^^^^^ expected `Simd<u32, 4>`, found `Simd<u8, 4>` + | + = note: expected struct `Simd<u32, _>` + found struct `Simd<u8, _>` +help: the return type of this call is `Simd<u8, 4>` due to the type of the argument passed + --> $DIR/masked-load-store-check-fail.rs:25:32 + | +LL | let _x: Simd<u32, 4> = simd_masked_load( + | ________________________________^ +LL | | Simd::<u8, 4>([1, 0, 1, 1]), +LL | | arr.as_ptr(), +LL | | default + | | ------- this argument influences the return type of `simd_masked_load` +LL | | ); + | |_________^ +note: function defined here + --> $DIR/masked-load-store-check-fail.rs:5:8 + | +LL | fn simd_masked_load<M, P, T>(mask: M, pointer: P, values: T) -> T; + | ^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/simd/masked-load-store.rs b/tests/ui/simd/masked-load-store.rs new file mode 100644 index 000000000..74ee652ec --- /dev/null +++ b/tests/ui/simd/masked-load-store.rs @@ -0,0 +1,33 @@ +// run-pass +#![feature(repr_simd, platform_intrinsics)] + +extern "platform-intrinsic" { + fn simd_masked_load<M, P, T>(mask: M, pointer: P, values: T) -> T; + fn simd_masked_store<M, P, T>(mask: M, pointer: P, values: T) -> (); +} + +#[derive(Copy, Clone)] +#[repr(simd)] +struct Simd<T, const N: usize>([T; N]); + +fn main() { + unsafe { + let a = Simd::<u8, 4>([0, 1, 2, 3]); + let b_src = [4u8, 5, 6, 7]; + let b_default = Simd::<u8, 4>([9; 4]); + let b: Simd::<u8, 4> = simd_masked_load( + Simd::<i8, 4>([-1, 0, -1, -1]), + b_src.as_ptr(), + b_default + ); + + assert_eq!(&b.0, &[4, 9, 6, 7]); + + let mut output = [u8::MAX; 5]; + + simd_masked_store(Simd::<i8, 4>([-1, -1, -1, 0]), output.as_mut_ptr(), a); + assert_eq!(&output, &[0, 1, 2, u8::MAX, u8::MAX]); + simd_masked_store(Simd::<i8, 4>([0, -1, -1, 0]), output[1..].as_mut_ptr(), b); + assert_eq!(&output, &[0, 1, 9, 6, u8::MAX]); + } +} diff --git a/tests/ui/simd/monomorphize-heterogeneous.stderr b/tests/ui/simd/monomorphize-heterogeneous.stderr index e7b41cd78..58e2b7c83 100644 --- a/tests/ui/simd/monomorphize-heterogeneous.stderr +++ b/tests/ui/simd/monomorphize-heterogeneous.stderr @@ -4,6 +4,6 @@ error[E0076]: SIMD vector should be homogeneous LL | struct I64F64(i64, f64); | ^^^^^^^^^^^^^ SIMD elements must have the same type -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0076`. diff --git a/tests/ui/simd/monomorphize-shuffle-index.generic.stderr b/tests/ui/simd/monomorphize-shuffle-index.generic.stderr index fc66b1956..c4cfca7be 100644 --- a/tests/ui/simd/monomorphize-shuffle-index.generic.stderr +++ b/tests/ui/simd/monomorphize-shuffle-index.generic.stderr @@ -8,5 +8,5 @@ LL | return simd_shuffle_generic::<_, _, { &Self::I }>(a, b); | = help: consider moving this anonymous constant into a `const` function -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/simd/portable-intrinsics-arent-exposed.stderr b/tests/ui/simd/portable-intrinsics-arent-exposed.stderr index f8b3e6d65..a6f27af42 100644 --- a/tests/ui/simd/portable-intrinsics-arent-exposed.stderr +++ b/tests/ui/simd/portable-intrinsics-arent-exposed.stderr @@ -2,9 +2,10 @@ error[E0433]: failed to resolve: maybe a missing crate `core`? --> $DIR/portable-intrinsics-arent-exposed.rs:4:5 | LL | use core::simd::intrinsics; - | ^^^^ maybe a missing crate `core`? - | - = help: consider adding `extern crate core` to use the `core` crate + | ^^^^ + | | + | maybe a missing crate `core`? + | help: try using `std` instead of `core`: `std` error[E0432]: unresolved import `std::simd::intrinsics` --> $DIR/portable-intrinsics-arent-exposed.rs:5:5 diff --git a/tests/ui/simd/repr_packed.rs b/tests/ui/simd/repr_packed.rs new file mode 100644 index 000000000..df2d59a58 --- /dev/null +++ b/tests/ui/simd/repr_packed.rs @@ -0,0 +1,59 @@ +// run-pass + +#![feature(repr_simd, platform_intrinsics)] +#![allow(non_camel_case_types)] + +#[repr(simd, packed)] +struct Simd<T, const N: usize>([T; N]); + +#[repr(simd)] +struct FullSimd<T, const N: usize>([T; N]); + +fn check_size_align<T, const N: usize>() { + use std::mem; + assert_eq!(mem::size_of::<Simd<T, N>>(), mem::size_of::<[T; N]>()); + assert_eq!(mem::size_of::<Simd<T, N>>() % mem::align_of::<Simd<T, N>>(), 0); +} + +fn check_ty<T>() { + check_size_align::<T, 1>(); + check_size_align::<T, 2>(); + check_size_align::<T, 3>(); + check_size_align::<T, 4>(); + check_size_align::<T, 8>(); + check_size_align::<T, 9>(); + check_size_align::<T, 15>(); +} + +extern "platform-intrinsic" { + fn simd_add<T>(a: T, b: T) -> T; +} + +fn main() { + check_ty::<u8>(); + check_ty::<i16>(); + check_ty::<u32>(); + check_ty::<i64>(); + check_ty::<usize>(); + check_ty::<f32>(); + check_ty::<f64>(); + + unsafe { + // powers-of-two have no padding and work as usual + let x: Simd<f64, 4> = + simd_add(Simd::<f64, 4>([0., 1., 2., 3.]), Simd::<f64, 4>([2., 2., 2., 2.])); + assert_eq!(std::mem::transmute::<_, [f64; 4]>(x), [2., 3., 4., 5.]); + + // non-powers-of-two have padding and need to be expanded to full vectors + fn load<T, const N: usize>(v: Simd<T, N>) -> FullSimd<T, N> { + unsafe { + let mut tmp = core::mem::MaybeUninit::<FullSimd<T, N>>::uninit(); + std::ptr::copy_nonoverlapping(&v as *const _, tmp.as_mut_ptr().cast(), 1); + tmp.assume_init() + } + } + let x: FullSimd<f64, 3> = + simd_add(load(Simd::<f64, 3>([0., 1., 2.])), load(Simd::<f64, 3>([2., 2., 2.]))); + assert_eq!(x.0, [2., 3., 4.]); + } +} diff --git a/tests/ui/simd/type-generic-monomorphisation-empty.stderr b/tests/ui/simd/type-generic-monomorphisation-empty.stderr index b334b1f4b..fc294607a 100644 --- a/tests/ui/simd/type-generic-monomorphisation-empty.stderr +++ b/tests/ui/simd/type-generic-monomorphisation-empty.stderr @@ -1,4 +1,4 @@ error: monomorphising SIMD type `Simd<0>` of zero length -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/simd/type-generic-monomorphisation-non-primitive.stderr b/tests/ui/simd/type-generic-monomorphisation-non-primitive.stderr index 9e8f06b82..249a14098 100644 --- a/tests/ui/simd/type-generic-monomorphisation-non-primitive.stderr +++ b/tests/ui/simd/type-generic-monomorphisation-non-primitive.stderr @@ -1,4 +1,4 @@ error: monomorphising SIMD type `S<E>` with a non-primitive-scalar (integer/float/pointer) element type `E` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/simd/type-generic-monomorphisation-oversized.stderr b/tests/ui/simd/type-generic-monomorphisation-oversized.stderr index a2dba1222..39ff36799 100644 --- a/tests/ui/simd/type-generic-monomorphisation-oversized.stderr +++ b/tests/ui/simd/type-generic-monomorphisation-oversized.stderr @@ -1,4 +1,4 @@ error: monomorphising SIMD type `Simd<65536>` of length greater than 32768 -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/simd/type-generic-monomorphisation-wide-ptr.stderr b/tests/ui/simd/type-generic-monomorphisation-wide-ptr.stderr index 3888e7a0f..7ac8d7153 100644 --- a/tests/ui/simd/type-generic-monomorphisation-wide-ptr.stderr +++ b/tests/ui/simd/type-generic-monomorphisation-wide-ptr.stderr @@ -1,4 +1,4 @@ error: monomorphising SIMD type `S<[*mut [u8]; 4]>` with a non-primitive-scalar (integer/float/pointer) element type `*mut [u8]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/simd/type-generic-monomorphisation.stderr b/tests/ui/simd/type-generic-monomorphisation.stderr index 7f23893ac..35297e17d 100644 --- a/tests/ui/simd/type-generic-monomorphisation.stderr +++ b/tests/ui/simd/type-generic-monomorphisation.stderr @@ -1,4 +1,4 @@ error: monomorphising SIMD type `Simd2<X>` with a non-primitive-scalar (integer/float/pointer) element type `X` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/tests/ui/simd/type-wide-ptr.stderr b/tests/ui/simd/type-wide-ptr.stderr index 51d3c0050..d2ce0fdd2 100644 --- a/tests/ui/simd/type-wide-ptr.stderr +++ b/tests/ui/simd/type-wide-ptr.stderr @@ -1,4 +1,4 @@ error: monomorphising SIMD type `S` with a non-primitive-scalar (integer/float/pointer) element type `*mut [u8]` -error: aborting due to previous error +error: aborting due to 1 previous error |