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