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