|
| 1 | +//@ run-pass |
| 2 | + |
| 3 | +// these tests are copied from `tests/ui/simd/intrinsic/generic-elements-pass.rs` |
| 4 | +#![feature(repr_simd, intrinsics, core_intrinsics)] |
| 5 | + |
| 6 | +#[path = "../../../../auxiliary/minisimd.rs"] |
| 7 | +mod minisimd; |
| 8 | +use std::intrinsics::simd::simd_shuffle; |
| 9 | + |
| 10 | +use minisimd::*; |
| 11 | + |
| 12 | +#[repr(simd)] |
| 13 | +struct SimdShuffleIdx<const LEN: usize>([u32; LEN]); |
| 14 | + |
| 15 | +macro_rules! all_eq { |
| 16 | + ($a: expr, $b: expr) => {{ |
| 17 | + let a = $a; |
| 18 | + let b = $b; |
| 19 | + // type inference works better with the concrete type on the |
| 20 | + // left, but humans work better with the expected on the |
| 21 | + // right. |
| 22 | + assert!(b == a, "{:?} != {:?}", a, b); |
| 23 | + }}; |
| 24 | +} |
| 25 | + |
| 26 | +macro_rules! simd_shuffle { |
| 27 | + ($a: expr, $b: expr, $shuffle: expr) => { |
| 28 | + const { simd_shuffle($a, $b, const { SimdShuffleIdx($shuffle) } ) } |
| 29 | + }; |
| 30 | +} |
| 31 | + |
| 32 | +fn main() { |
| 33 | + const X2: i32x2 = i32x2::from_array([20, 21]); |
| 34 | + const X4: i32x4 = i32x4::from_array([40, 41, 42, 43]); |
| 35 | + const X8: i32x8 = i32x8::from_array([80, 81, 82, 83, 84, 85, 86, 87]); |
| 36 | + |
| 37 | + const Y2: i32x2 = i32x2::from_array([120, 121]); |
| 38 | + const Y4: i32x4 = i32x4::from_array([140, 141, 142, 143]); |
| 39 | + const Y8: i32x8 = i32x8::from_array([180, 181, 182, 183, 184, 185, 186, 187]); |
| 40 | + unsafe { |
| 41 | + all_eq!(simd_shuffle!(X2, Y2, [3, 0]), i32x2::from_array([121, 20])); |
| 42 | + all_eq!(simd_shuffle!(X2, Y2, [3, 0, 1, 2]), i32x4::from_array([121, 20, 21, 120])); |
| 43 | + all_eq!( |
| 44 | + simd_shuffle!(X2, Y2, [3, 0, 1, 2, 1, 2, 3, 0]), |
| 45 | + i32x8::from_array([121, 20, 21, 120, 21, 120, 121, 20]) |
| 46 | + ); |
| 47 | + |
| 48 | + all_eq!(simd_shuffle!(X4, Y4, [7, 2]), i32x2::from_array([143, 42])); |
| 49 | + all_eq!(simd_shuffle!(X4, Y4, [7, 2, 5, 0]), i32x4::from_array([143, 42, 141, 40])); |
| 50 | + all_eq!( |
| 51 | + simd_shuffle!(X4, Y4, [7, 2, 5, 0, 3, 6, 4, 1]), |
| 52 | + i32x8::from_array([143, 42, 141, 40, 43, 142, 140, 41]) |
| 53 | + ); |
| 54 | + |
| 55 | + all_eq!(simd_shuffle!(X8, Y8, [11, 5]), i32x2::from_array([183, 85])); |
| 56 | + all_eq!(simd_shuffle!(X8, Y8, [11, 5, 15, 0]), i32x4::from_array([183, 85, 187, 80])); |
| 57 | + all_eq!( |
| 58 | + simd_shuffle!(X8, Y8, [11, 5, 15, 0, 3, 8, 12, 1]), |
| 59 | + i32x8::from_array([183, 85, 187, 80, 83, 180, 184, 81]) |
| 60 | + ); |
| 61 | + } |
| 62 | +} |
0 commit comments