]> git.lizzy.rs Git - rust.git/blob - library/std/tests/run-time-detect.rs
Rollup merge of #107284 - notriddle:notriddle/plus, r=jsha
[rust.git] / library / std / tests / run-time-detect.rs
1 //! These tests just check that the macros are available in std.
2
3 #![cfg_attr(
4     any(
5         all(target_arch = "arm", any(target_os = "linux", target_os = "android")),
6         all(target_arch = "powerpc", target_os = "linux"),
7         all(target_arch = "powerpc64", target_os = "linux"),
8     ),
9     feature(stdsimd)
10 )]
11
12 #[test]
13 #[cfg(all(target_arch = "arm", any(target_os = "linux", target_os = "android")))]
14 fn arm_linux() {
15     use std::arch::is_arm_feature_detected;
16     // tidy-alphabetical-start
17     println!("aes: {}", is_arm_feature_detected!("aes"));
18     println!("crc: {}", is_arm_feature_detected!("crc"));
19     println!("crypto: {}", is_arm_feature_detected!("crypto"));
20     println!("neon: {}", is_arm_feature_detected!("neon"));
21     println!("pmull: {}", is_arm_feature_detected!("pmull"));
22     println!("sha2: {}", is_arm_feature_detected!("sha2"));
23     // tidy-alphabetical-end
24 }
25
26 #[test]
27 #[cfg(all(target_arch = "aarch64", any(target_os = "linux", target_os = "android")))]
28 fn aarch64_linux() {
29     use std::arch::is_aarch64_feature_detected;
30     // tidy-alphabetical-start
31     println!("aes: {}", is_aarch64_feature_detected!("aes"));
32     println!("asimd: {}", is_aarch64_feature_detected!("asimd"));
33     println!("bf16: {}", is_aarch64_feature_detected!("bf16"));
34     println!("bti: {}", is_aarch64_feature_detected!("bti"));
35     println!("crc: {}", is_aarch64_feature_detected!("crc"));
36     println!("dit: {}", is_aarch64_feature_detected!("dit"));
37     println!("dotprod: {}", is_aarch64_feature_detected!("dotprod"));
38     println!("dpb2: {}", is_aarch64_feature_detected!("dpb2"));
39     println!("dpb: {}", is_aarch64_feature_detected!("dpb"));
40     println!("f32mm: {}", is_aarch64_feature_detected!("f32mm"));
41     println!("f64mm: {}", is_aarch64_feature_detected!("f64mm"));
42     println!("fcma: {}", is_aarch64_feature_detected!("fcma"));
43     println!("fhm: {}", is_aarch64_feature_detected!("fhm"));
44     println!("flagm: {}", is_aarch64_feature_detected!("flagm"));
45     println!("fp16: {}", is_aarch64_feature_detected!("fp16"));
46     println!("frintts: {}", is_aarch64_feature_detected!("frintts"));
47     println!("i8mm: {}", is_aarch64_feature_detected!("i8mm"));
48     println!("jsconv: {}", is_aarch64_feature_detected!("jsconv"));
49     println!("lse2: {}", is_aarch64_feature_detected!("lse2"));
50     println!("lse: {}", is_aarch64_feature_detected!("lse"));
51     println!("mte: {}", is_aarch64_feature_detected!("mte"));
52     println!("neon: {}", is_aarch64_feature_detected!("neon"));
53     println!("paca: {}", is_aarch64_feature_detected!("paca"));
54     println!("pacg: {}", is_aarch64_feature_detected!("pacg"));
55     println!("pmull: {}", is_aarch64_feature_detected!("pmull"));
56     println!("rand: {}", is_aarch64_feature_detected!("rand"));
57     println!("rcpc2: {}", is_aarch64_feature_detected!("rcpc2"));
58     println!("rcpc: {}", is_aarch64_feature_detected!("rcpc"));
59     println!("rdm: {}", is_aarch64_feature_detected!("rdm"));
60     println!("sb: {}", is_aarch64_feature_detected!("sb"));
61     println!("sha2: {}", is_aarch64_feature_detected!("sha2"));
62     println!("sha3: {}", is_aarch64_feature_detected!("sha3"));
63     println!("sm4: {}", is_aarch64_feature_detected!("sm4"));
64     println!("ssbs: {}", is_aarch64_feature_detected!("ssbs"));
65     println!("sve2-aes: {}", is_aarch64_feature_detected!("sve2-aes"));
66     println!("sve2-bitperm: {}", is_aarch64_feature_detected!("sve2-bitperm"));
67     println!("sve2-sha3: {}", is_aarch64_feature_detected!("sve2-sha3"));
68     println!("sve2-sm4: {}", is_aarch64_feature_detected!("sve2-sm4"));
69     println!("sve2: {}", is_aarch64_feature_detected!("sve2"));
70     println!("sve: {}", is_aarch64_feature_detected!("sve"));
71     println!("tme: {}", is_aarch64_feature_detected!("tme"));
72     // tidy-alphabetical-end
73 }
74
75 #[test]
76 #[cfg(all(target_arch = "powerpc", target_os = "linux"))]
77 fn powerpc_linux() {
78     use std::arch::is_powerpc_feature_detected;
79     // tidy-alphabetical-start
80     println!("altivec: {}", is_powerpc_feature_detected!("altivec"));
81     println!("power8: {}", is_powerpc_feature_detected!("power8"));
82     println!("vsx: {}", is_powerpc_feature_detected!("vsx"));
83     // tidy-alphabetical-end
84 }
85
86 #[test]
87 #[cfg(all(target_arch = "powerpc64", target_os = "linux"))]
88 fn powerpc64_linux() {
89     use std::arch::is_powerpc64_feature_detected;
90     // tidy-alphabetical-start
91     println!("altivec: {}", is_powerpc64_feature_detected!("altivec"));
92     println!("power8: {}", is_powerpc64_feature_detected!("power8"));
93     println!("vsx: {}", is_powerpc64_feature_detected!("vsx"));
94     // tidy-alphabetical-end
95 }
96
97 #[test]
98 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
99 fn x86_all() {
100     use std::arch::is_x86_feature_detected;
101
102     // the below is the set of features we can test at runtime, but don't actually
103     // use to gate anything and are thus not part of the X86_ALLOWED_FEATURES list
104
105     println!("abm: {:?}", is_x86_feature_detected!("abm")); // this is a synonym for lzcnt but we test it anyways
106     println!("mmx: {:?}", is_x86_feature_detected!("mmx"));
107     println!("tsc: {:?}", is_x86_feature_detected!("tsc"));
108
109     // the below is in alphabetical order and matches
110     // the order of X86_ALLOWED_FEATURES in rustc_codegen_ssa's target_features.rs
111
112     // tidy-alphabetical-start
113     println!("adx: {:?}", is_x86_feature_detected!("adx"));
114     println!("aes: {:?}", is_x86_feature_detected!("aes"));
115     println!("avx2: {:?}", is_x86_feature_detected!("avx2"));
116     println!("avx512bf16: {:?}", is_x86_feature_detected!("avx512bf16"));
117     println!("avx512bitalg: {:?}", is_x86_feature_detected!("avx512bitalg"));
118     println!("avx512bw: {:?}", is_x86_feature_detected!("avx512bw"));
119     println!("avx512cd: {:?}", is_x86_feature_detected!("avx512cd"));
120     println!("avx512dq: {:?}", is_x86_feature_detected!("avx512dq"));
121     println!("avx512er: {:?}", is_x86_feature_detected!("avx512er"));
122     println!("avx512f: {:?}", is_x86_feature_detected!("avx512f"));
123     println!("avx512ifma: {:?}", is_x86_feature_detected!("avx512ifma"));
124     println!("avx512pf: {:?}", is_x86_feature_detected!("avx512pf"));
125     println!("avx512vbmi2: {:?}", is_x86_feature_detected!("avx512vbmi2"));
126     println!("avx512vbmi: {:?}", is_x86_feature_detected!("avx512vbmi"));
127     println!("avx512vl: {:?}", is_x86_feature_detected!("avx512vl"));
128     println!("avx512vnni: {:?}", is_x86_feature_detected!("avx512vnni"));
129     println!("avx512vp2intersect: {:?}", is_x86_feature_detected!("avx512vp2intersect"));
130     println!("avx512vpopcntdq: {:?}", is_x86_feature_detected!("avx512vpopcntdq"));
131     println!("avx: {:?}", is_x86_feature_detected!("avx"));
132     println!("bmi1: {:?}", is_x86_feature_detected!("bmi1"));
133     println!("bmi2: {:?}", is_x86_feature_detected!("bmi2"));
134     println!("cmpxchg16b: {:?}", is_x86_feature_detected!("cmpxchg16b"));
135     println!("f16c: {:?}", is_x86_feature_detected!("f16c"));
136     println!("fma: {:?}", is_x86_feature_detected!("fma"));
137     println!("fxsr: {:?}", is_x86_feature_detected!("fxsr"));
138     println!("gfni: {:?}", is_x86_feature_detected!("gfni"));
139     println!("lzcnt: {:?}", is_x86_feature_detected!("lzcnt"));
140     //println!("movbe: {:?}", is_x86_feature_detected!("movbe")); // movbe is unsupported as a target feature
141     println!("pclmulqdq: {:?}", is_x86_feature_detected!("pclmulqdq"));
142     println!("popcnt: {:?}", is_x86_feature_detected!("popcnt"));
143     println!("rdrand: {:?}", is_x86_feature_detected!("rdrand"));
144     println!("rdseed: {:?}", is_x86_feature_detected!("rdseed"));
145     println!("rtm: {:?}", is_x86_feature_detected!("rtm"));
146     println!("sha: {:?}", is_x86_feature_detected!("sha"));
147     println!("sse2: {:?}", is_x86_feature_detected!("sse2"));
148     println!("sse3: {:?}", is_x86_feature_detected!("sse3"));
149     println!("sse4.1: {:?}", is_x86_feature_detected!("sse4.1"));
150     println!("sse4.2: {:?}", is_x86_feature_detected!("sse4.2"));
151     println!("sse4a: {:?}", is_x86_feature_detected!("sse4a"));
152     println!("sse: {:?}", is_x86_feature_detected!("sse"));
153     println!("ssse3: {:?}", is_x86_feature_detected!("ssse3"));
154     println!("tbm: {:?}", is_x86_feature_detected!("tbm"));
155     println!("vaes: {:?}", is_x86_feature_detected!("vaes"));
156     println!("vpclmulqdq: {:?}", is_x86_feature_detected!("vpclmulqdq"));
157     println!("xsave: {:?}", is_x86_feature_detected!("xsave"));
158     println!("xsavec: {:?}", is_x86_feature_detected!("xsavec"));
159     println!("xsaveopt: {:?}", is_x86_feature_detected!("xsaveopt"));
160     println!("xsaves: {:?}", is_x86_feature_detected!("xsaves"));
161     // tidy-alphabetical-end
162 }