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