]> git.lizzy.rs Git - rust.git/blob - src/test/ui/simd/target-feature-mixup.rs
Rollup merge of #89509 - jhpratt:stabilize-const_unreachable_unchecked, r=oli-obk
[rust.git] / src / test / ui / simd / target-feature-mixup.rs
1 // run-pass
2 #![allow(unused_variables)]
3 #![allow(stable_features)]
4 #![allow(overflowing_literals)]
5
6 // ignore-emscripten
7 // ignore-sgx no processes
8
9 #![feature(repr_simd, target_feature, cfg_target_feature)]
10 #![feature(avx512_target_feature)]
11
12 use std::process::{Command, ExitStatus};
13 use std::env;
14
15 fn main() {
16     if let Some(level) = env::args().nth(1) {
17         return test::main(&level)
18     }
19
20     let me = env::current_exe().unwrap();
21     for level in ["sse", "avx", "avx512"].iter() {
22         let status = Command::new(&me).arg(level).status().unwrap();
23         if status.success() {
24             println!("success with {}", level);
25             continue
26         }
27
28         // We don't actually know if our computer has the requisite target features
29         // for the test below. Testing for that will get added to libstd later so
30         // for now just assume sigill means this is a machine that can't run this test.
31         if is_sigill(status) {
32             println!("sigill with {}, assuming spurious", level);
33             continue
34         }
35         panic!("invalid status at {}: {}", level, status);
36     }
37 }
38
39 #[cfg(unix)]
40 fn is_sigill(status: ExitStatus) -> bool {
41     use std::os::unix::prelude::*;
42     status.signal() == Some(4)
43 }
44
45 #[cfg(windows)]
46 fn is_sigill(status: ExitStatus) -> bool {
47     status.code() == Some(0xc000001d)
48 }
49
50 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
51 #[allow(nonstandard_style)]
52 mod test {
53     // An SSE type
54     #[repr(simd)]
55     #[derive(PartialEq, Debug, Clone, Copy)]
56     struct __m128i(u64, u64);
57
58     // An AVX type
59     #[repr(simd)]
60     #[derive(PartialEq, Debug, Clone, Copy)]
61     struct __m256i(u64, u64, u64, u64);
62
63     // An AVX-512 type
64     #[repr(simd)]
65     #[derive(PartialEq, Debug, Clone, Copy)]
66     struct __m512i(u64, u64, u64, u64, u64, u64, u64, u64);
67
68     pub fn main(level: &str) {
69         unsafe {
70             main_normal(level);
71             main_sse(level);
72             if level == "sse" {
73                 return
74             }
75             main_avx(level);
76             if level == "avx" {
77                 return
78             }
79             main_avx512(level);
80         }
81     }
82
83     macro_rules! mains {
84         ($(
85             $(#[$attr:meta])*
86             unsafe fn $main:ident(level: &str) {
87                 ...
88             }
89         )*) => ($(
90             $(#[$attr])*
91             unsafe fn $main(level: &str) {
92                 let m128 = __m128i(1, 2);
93                 let m256 = __m256i(3, 4, 5, 6);
94                 let m512 = __m512i(7, 8, 9, 10, 11, 12, 13, 14);
95                 assert_eq!(id_sse_128(m128), m128);
96                 assert_eq!(id_sse_256(m256), m256);
97                 assert_eq!(id_sse_512(m512), m512);
98
99                 if level == "sse" {
100                     return
101                 }
102                 assert_eq!(id_avx_128(m128), m128);
103                 assert_eq!(id_avx_256(m256), m256);
104                 assert_eq!(id_avx_512(m512), m512);
105
106                 if level == "avx" {
107                     return
108                 }
109                 assert_eq!(id_avx512_128(m128), m128);
110                 assert_eq!(id_avx512_256(m256), m256);
111                 assert_eq!(id_avx512_512(m512), m512);
112             }
113         )*)
114     }
115
116     mains! {
117         unsafe fn main_normal(level: &str) { ... }
118         #[target_feature(enable = "sse2")]
119         unsafe fn main_sse(level: &str) { ... }
120         #[target_feature(enable = "avx")]
121         unsafe fn main_avx(level: &str) { ... }
122         #[target_feature(enable = "avx512bw")]
123         unsafe fn main_avx512(level: &str) { ... }
124     }
125
126
127     #[target_feature(enable = "sse2")]
128     unsafe fn id_sse_128(a: __m128i) -> __m128i {
129         assert_eq!(a, __m128i(1, 2));
130         a.clone()
131     }
132
133     #[target_feature(enable = "sse2")]
134     unsafe fn id_sse_256(a: __m256i) -> __m256i {
135         assert_eq!(a, __m256i(3, 4, 5, 6));
136         a.clone()
137     }
138
139     #[target_feature(enable = "sse2")]
140     unsafe fn id_sse_512(a: __m512i) -> __m512i {
141         assert_eq!(a, __m512i(7, 8, 9, 10, 11, 12, 13, 14));
142         a.clone()
143     }
144
145     #[target_feature(enable = "avx")]
146     unsafe fn id_avx_128(a: __m128i) -> __m128i {
147         assert_eq!(a, __m128i(1, 2));
148         a.clone()
149     }
150
151     #[target_feature(enable = "avx")]
152     unsafe fn id_avx_256(a: __m256i) -> __m256i {
153         assert_eq!(a, __m256i(3, 4, 5, 6));
154         a.clone()
155     }
156
157     #[target_feature(enable = "avx")]
158     unsafe fn id_avx_512(a: __m512i) -> __m512i {
159         assert_eq!(a, __m512i(7, 8, 9, 10, 11, 12, 13, 14));
160         a.clone()
161     }
162
163     #[target_feature(enable = "avx512bw")]
164     unsafe fn id_avx512_128(a: __m128i) -> __m128i {
165         assert_eq!(a, __m128i(1, 2));
166         a.clone()
167     }
168
169     #[target_feature(enable = "avx512bw")]
170     unsafe fn id_avx512_256(a: __m256i) -> __m256i {
171         assert_eq!(a, __m256i(3, 4, 5, 6));
172         a.clone()
173     }
174
175     #[target_feature(enable = "avx512bw")]
176     unsafe fn id_avx512_512(a: __m512i) -> __m512i {
177         assert_eq!(a, __m512i(7, 8, 9, 10, 11, 12, 13, 14));
178         a.clone()
179     }
180 }
181
182 #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
183 mod test {
184     pub fn main(level: &str) {}
185 }