1
- //run-pass
1
+ // run-pass
2
+ // revisions: opt noopt
3
+ //[noopt] compile-flags: -Copt-level=0
4
+ //[opt] compile-flags: -O
2
5
#![ feature( repr_simd, platform_intrinsics) ]
6
+ #![ allow( incomplete_features) ]
7
+ #![ feature( adt_const_params) ]
3
8
4
9
extern "platform-intrinsic" {
5
10
fn simd_shuffle < T , I , U > ( a : T , b : T , i : I ) -> U ;
11
+ fn simd_shuffle16 < T , U > ( x : T , y : T , idx : [ u32 ; 16 ] ) -> U ;
6
12
}
7
13
8
14
#[ derive( Copy , Clone ) ]
9
15
#[ repr( simd) ]
10
16
struct Simd < T , const N : usize > ( [ T ; N ] ) ;
11
17
18
+ pub unsafe fn __shuffle_vector16 < const IDX : [ u32 ; 16 ] , T , U > ( x : T , y : T ) -> U {
19
+ simd_shuffle16 ( x, y, IDX )
20
+ }
21
+
12
22
fn main ( ) {
13
23
const I1 : [ u32 ; 4 ] = [ 0 , 2 , 4 , 6 ] ;
14
24
const I2 : [ u32 ; 2 ] = [ 1 , 5 ] ;
@@ -21,4 +31,16 @@ fn main() {
21
31
let y: Simd < u8 , 2 > = simd_shuffle ( a, b, I2 ) ;
22
32
assert_eq ! ( y. 0 , [ 1 , 5 ] ) ;
23
33
}
34
+ // Test that an indirection (via an unnamed constant)
35
+ // through a const generic parameter also works.
36
+ // See https://github.com/rust-lang/rust/issues/113500 for details.
37
+ let a = Simd :: < u8 , 16 > ( [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ] ) ;
38
+ let b = Simd :: < u8 , 16 > ( [ 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 ] ) ;
39
+ unsafe {
40
+ __shuffle_vector16 :: <
41
+ { [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ] } ,
42
+ Simd < u8 , 16 > ,
43
+ Simd < u8 , 16 > ,
44
+ > ( a, b) ;
45
+ }
24
46
}
0 commit comments