]> git.lizzy.rs Git - rust.git/blob - src/test/ui/simd/simd-intrinsic-generic-elements.rs
Auto merge of #84589 - In-line:zircon-thread-name, r=JohnTitor
[rust.git] / src / test / ui / simd / simd-intrinsic-generic-elements.rs
1 // run-pass
2 // ignore-emscripten FIXME(#45351) hits an LLVM assert
3
4 #![feature(repr_simd, platform_intrinsics)]
5 #![allow(incomplete_features)]
6 #![feature(inline_const)]
7
8 #[repr(simd)]
9 #[derive(Copy, Clone, Debug, PartialEq)]
10 #[allow(non_camel_case_types)]
11 struct i32x2(i32, i32);
12 #[repr(simd)]
13 #[derive(Copy, Clone, Debug, PartialEq)]
14 #[allow(non_camel_case_types)]
15 struct i32x4(i32, i32, i32, i32);
16 #[repr(simd)]
17 #[derive(Copy, Clone, Debug, PartialEq)]
18 #[allow(non_camel_case_types)]
19 struct i32x8(i32, i32, i32, i32,
20              i32, i32, i32, i32);
21
22 extern "platform-intrinsic" {
23     fn simd_insert<T, E>(x: T, idx: u32, y: E) -> T;
24     fn simd_extract<T, E>(x: T, idx: u32) -> E;
25
26     fn simd_shuffle2<T, U>(x: T, y: T, idx: [u32; 2]) -> U;
27     fn simd_shuffle4<T, U>(x: T, y: T, idx: [u32; 4]) -> U;
28     fn simd_shuffle8<T, U>(x: T, y: T, idx: [u32; 8]) -> U;
29 }
30
31 macro_rules! all_eq {
32     ($a: expr, $b: expr) => {{
33         let a = $a;
34         let b = $b;
35         // type inference works better with the concrete type on the
36         // left, but humans work better with the expected on the
37         // right.
38         assert!(b == a,
39                 "{:?} != {:?}", a, b);
40     }}
41 }
42
43 fn main() {
44     let x2 = i32x2(20, 21);
45     let x4 = i32x4(40, 41, 42, 43);
46     let x8 = i32x8(80, 81, 82, 83, 84, 85, 86, 87);
47     unsafe {
48         all_eq!(simd_insert(x2, 0, 100), i32x2(100, 21));
49         all_eq!(simd_insert(x2, 1, 100), i32x2(20, 100));
50
51         all_eq!(simd_insert(x4, 0, 100), i32x4(100, 41, 42, 43));
52         all_eq!(simd_insert(x4, 1, 100), i32x4(40, 100, 42, 43));
53         all_eq!(simd_insert(x4, 2, 100), i32x4(40, 41, 100, 43));
54         all_eq!(simd_insert(x4, 3, 100), i32x4(40, 41, 42, 100));
55
56         all_eq!(simd_insert(x8, 0, 100), i32x8(100, 81, 82, 83, 84, 85, 86, 87));
57         all_eq!(simd_insert(x8, 1, 100), i32x8(80, 100, 82, 83, 84, 85, 86, 87));
58         all_eq!(simd_insert(x8, 2, 100), i32x8(80, 81, 100, 83, 84, 85, 86, 87));
59         all_eq!(simd_insert(x8, 3, 100), i32x8(80, 81, 82, 100, 84, 85, 86, 87));
60         all_eq!(simd_insert(x8, 4, 100), i32x8(80, 81, 82, 83, 100, 85, 86, 87));
61         all_eq!(simd_insert(x8, 5, 100), i32x8(80, 81, 82, 83, 84, 100, 86, 87));
62         all_eq!(simd_insert(x8, 6, 100), i32x8(80, 81, 82, 83, 84, 85, 100, 87));
63         all_eq!(simd_insert(x8, 7, 100), i32x8(80, 81, 82, 83, 84, 85, 86, 100));
64
65         all_eq!(simd_extract(x2, 0), 20);
66         all_eq!(simd_extract(x2, 1), 21);
67
68         all_eq!(simd_extract(x4, 0), 40);
69         all_eq!(simd_extract(x4, 1), 41);
70         all_eq!(simd_extract(x4, 2), 42);
71         all_eq!(simd_extract(x4, 3), 43);
72
73         all_eq!(simd_extract(x8, 0), 80);
74         all_eq!(simd_extract(x8, 1), 81);
75         all_eq!(simd_extract(x8, 2), 82);
76         all_eq!(simd_extract(x8, 3), 83);
77         all_eq!(simd_extract(x8, 4), 84);
78         all_eq!(simd_extract(x8, 5), 85);
79         all_eq!(simd_extract(x8, 6), 86);
80         all_eq!(simd_extract(x8, 7), 87);
81     }
82
83     let y2 = i32x2(120, 121);
84     let y4 = i32x4(140, 141, 142, 143);
85     let y8 = i32x8(180, 181, 182, 183, 184, 185, 186, 187);
86     unsafe {
87         all_eq!(simd_shuffle2(x2, y2, const { [3u32, 0] }), i32x2(121, 20));
88         all_eq!(simd_shuffle4(x2, y2, const { [3u32, 0, 1, 2] }), i32x4(121, 20, 21, 120));
89         all_eq!(simd_shuffle8(x2, y2, const { [3u32, 0, 1, 2, 1, 2, 3, 0] }),
90                 i32x8(121, 20, 21, 120, 21, 120, 121, 20));
91
92         all_eq!(simd_shuffle2(x4, y4, const { [7u32, 2] }), i32x2(143, 42));
93         all_eq!(simd_shuffle4(x4, y4, const { [7u32, 2, 5, 0] }), i32x4(143, 42, 141, 40));
94         all_eq!(simd_shuffle8(x4, y4, const { [7u32, 2, 5, 0, 3, 6, 4, 1] }),
95                 i32x8(143, 42, 141, 40, 43, 142, 140, 41));
96
97         all_eq!(simd_shuffle2(x8, y8, const { [11u32, 5] }), i32x2(183, 85));
98         all_eq!(simd_shuffle4(x8, y8, const { [11u32, 5, 15, 0] }), i32x4(183, 85, 187, 80));
99         all_eq!(simd_shuffle8(x8, y8, const { [11u32, 5, 15, 0, 3, 8, 12, 1] }),
100                 i32x8(183, 85, 187, 80, 83, 180, 184, 81));
101     }
102
103 }