]> git.lizzy.rs Git - rust.git/blob - library/std/tests/run-time-detect.rs
Rollup merge of #93382 - GuillaumeGomez:search-input-padding, r=jsha
[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!("fp: {}", is_aarch64_feature_detected!("fp"));
33     println!("fp16: {}", is_aarch64_feature_detected!("fp16"));
34     println!("sve: {}", is_aarch64_feature_detected!("sve"));
35     println!("crc: {}", is_aarch64_feature_detected!("crc"));
36     println!("lse: {}", is_aarch64_feature_detected!("lse"));
37     println!("lse2: {}", is_aarch64_feature_detected!("lse2"));
38     println!("rdm: {}", is_aarch64_feature_detected!("rdm"));
39     println!("rcpc: {}", is_aarch64_feature_detected!("rcpc"));
40     println!("rcpc2: {}", is_aarch64_feature_detected!("rcpc2"));
41     println!("dotprod: {}", is_aarch64_feature_detected!("dotprod"));
42     println!("tme: {}", is_aarch64_feature_detected!("tme"));
43     println!("fhm: {}", is_aarch64_feature_detected!("fhm"));
44     println!("dit: {}", is_aarch64_feature_detected!("dit"));
45     println!("flagm: {}", is_aarch64_feature_detected!("flagm"));
46     println!("ssbs: {}", is_aarch64_feature_detected!("ssbs"));
47     println!("sb: {}", is_aarch64_feature_detected!("sb"));
48     println!("paca: {}", is_aarch64_feature_detected!("paca"));
49     println!("pacg: {}", is_aarch64_feature_detected!("pacg"));
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 }