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