Skip to content

Commit 93b9957

Browse files
authored
Add cfg! clauses to detection macro (rust-lang#351)
This way if the feature is statically detected then it'll be expanded to `true` Closes rust-lang#349
1 parent 390f5d6 commit 93b9957

File tree

5 files changed

+72
-54
lines changed

5 files changed

+72
-54
lines changed

crates/stdsimd/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//! [stdsimd]: https://rust-lang-nursery.github.io/stdsimd/x86_64/stdsimd/
99
1010
#![feature(const_fn, integer_atomics, staged_api, stdsimd)]
11+
#![feature(cfg_target_feature)]
1112
#![cfg_attr(feature = "cargo-clippy", allow(shadow_reuse))]
1213
#![cfg_attr(target_os = "linux", feature(linkage))]
1314
#![no_std]

stdsimd/arch/detect/aarch64.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,52 @@ use super::linux;
99
macro_rules! is_aarch64_feature_detected {
1010
("neon") => {
1111
// FIXME: this should be removed once we rename Aarch64 neon to asimd
12-
$crate::arch::detect::check_for($crate::arch::detect::Feature::asimd)
12+
cfg!(target_feature = "neon") ||
13+
$crate::arch::detect::check_for($crate::arch::detect::Feature::asimd)
1314
};
1415
("asimd") => {
15-
$crate::arch::detect::check_for($crate::arch::detect::Feature::asimd)
16+
cfg!(target_feature = "neon") ||
17+
$crate::arch::detect::check_for($crate::arch::detect::Feature::asimd)
1618
};
1719
("pmull") => {
18-
$crate::arch::detect::check_for($crate::arch::detect::Feature::pmull)
20+
cfg!(target_feature = "pmull") ||
21+
$crate::arch::detect::check_for($crate::arch::detect::Feature::pmull)
1922
};
2023
("fp") => {
21-
$crate::arch::detect::check_for($crate::arch::detect::Feature::fp)
24+
cfg!(target_feature = "fp") ||
25+
$crate::arch::detect::check_for($crate::arch::detect::Feature::fp)
2226
};
2327
("fp16") => {
24-
$crate::arch::detect::check_for($crate::arch::detect::Feature::fp16)
28+
cfg!(target_feature = "fp16") ||
29+
$crate::arch::detect::check_for($crate::arch::detect::Feature::fp16)
2530
};
2631
("sve") => {
27-
$crate::arch::detect::check_for($crate::arch::detect::Feature::sve)
32+
cfg!(target_feature = "sve") ||
33+
$crate::arch::detect::check_for($crate::arch::detect::Feature::sve)
2834
};
2935
("crc") => {
30-
$crate::arch::detect::check_for($crate::arch::detect::Feature::crc)
36+
cfg!(target_feature = "crc") ||
37+
$crate::arch::detect::check_for($crate::arch::detect::Feature::crc)
3138
};
3239
("crypto") => {
33-
$crate::arch::detect::check_for($crate::arch::detect::Feature::crypto)
40+
cfg!(target_feature = "crypto") ||
41+
$crate::arch::detect::check_for($crate::arch::detect::Feature::crypto)
3442
};
3543
("lse") => {
36-
$crate::arch::detect::check_for($crate::arch::detect::Feature::lse)
44+
cfg!(target_feature = "lse") ||
45+
$crate::arch::detect::check_for($crate::arch::detect::Feature::lse)
3746
};
3847
("rdm") => {
39-
$crate::arch::detect::check_for($crate::arch::detect::Feature::rdm)
48+
cfg!(target_feature = "rdm") ||
49+
$crate::arch::detect::check_for($crate::arch::detect::Feature::rdm)
4050
};
4151
("rcpc") => {
42-
$crate::arch::detect::check_for($crate::arch::detect::Feature::rcpc)
52+
cfg!(target_feature = "rcpc") ||
53+
$crate::arch::detect::check_for($crate::arch::detect::Feature::rcpc)
4354
};
4455
("dotprod") => {
45-
$crate::arch::detect::check_for($crate::arch::detect::Feature::dotprod)
56+
cfg!(target_feature = "dotprot") ||
57+
$crate::arch::detect::check_for($crate::arch::detect::Feature::dotprod)
4658
};
4759
("ras") => {
4860
compile_error!("\"ras\" feature cannot be detected at run-time")

stdsimd/arch/detect/arm.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ use super::linux;
88
#[unstable(feature = "stdsimd", issue = "0")]
99
macro_rules! is_arm_feature_detected {
1010
("neon") => {
11-
$crate::arch::detect::check_for($crate::arch::detect::Feature::neon)
11+
cfg!(target_feature = "neon") ||
12+
$crate::arch::detect::check_for($crate::arch::detect::Feature::neon)
1213
};
1314
("pmull") => {
14-
$crate::arch::detect::check_for($crate::arch::detect::Feature::pmull)
15+
cfg!(target_feature = "pmull") ||
16+
$crate::arch::detect::check_for($crate::arch::detect::Feature::pmull)
1517
};
1618
($t:tt) => { compile_error!(concat!("unknown arm target feature: ", $t)) };
1719
}

stdsimd/arch/detect/powerpc64.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ use super::linux;
77
#[unstable(feature = "stdsimd", issue = "0")]
88
macro_rules! is_powerpc64_feature_detected {
99
("altivec") => {
10-
$crate::arch::detect::check_for($crate::arch::detect::Feature::altivec)
10+
cfg!(target_feature = "altivec") ||
11+
$crate::arch::detect::check_for($crate::arch::detect::Feature::altivec)
1112
};
1213
("vsx") => {
13-
$crate::arch::detect::check_for($crate::arch::detect::Feature::vsx)
14+
cfg!(target_feature = "vsx") ||
15+
$crate::arch::detect::check_for($crate::arch::detect::Feature::vsx)
1416
};
1517
("power8") => {
16-
$crate::arch::detect::check_for($crate::arch::detect::Feature::power8)
18+
cfg!(target_feature = "power8") ||
19+
$crate::arch::detect::check_for($crate::arch::detect::Feature::power8)
1720
};
1821
($t:tt) => { compile_error!(concat!("unknown arm target feature: ", $t)) };
1922
}

stdsimd/arch/detect/x86.rs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,144 +29,144 @@ use super::{bit, cache};
2929
#[unstable(feature = "stdsimd", issue = "0")]
3030
macro_rules! is_x86_feature_detected {
3131
("aes") => {
32-
$crate::arch::detect::check_for(
32+
cfg!(target_feature = "aes") || $crate::arch::detect::check_for(
3333
$crate::arch::detect::Feature::aes) };
3434
("pclmulqdq") => {
35-
$crate::arch::detect::check_for(
35+
cfg!(target_feature = "pclmulqdq") || $crate::arch::detect::check_for(
3636
$crate::arch::detect::Feature::pclmulqdq) };
3737
("rdrand") => {
38-
$crate::arch::detect::check_for(
38+
cfg!(target_feature = "rdrand") || $crate::arch::detect::check_for(
3939
$crate::arch::detect::Feature::rdrand) };
4040
("rdseed") => {
41-
$crate::arch::detect::check_for(
41+
cfg!(target_feature = "rdseed") || $crate::arch::detect::check_for(
4242
$crate::arch::detect::Feature::rdseed) };
4343
("tsc") => {
44-
$crate::arch::detect::check_for(
44+
cfg!(target_feature = "tsc") || $crate::arch::detect::check_for(
4545
$crate::arch::detect::Feature::tsc) };
4646
("mmx") => {
47-
$crate::arch::detect::check_for(
47+
cfg!(target_feature = "mmx") || $crate::arch::detect::check_for(
4848
$crate::arch::detect::Feature::mmx) };
4949
("sse") => {
50-
$crate::arch::detect::check_for(
50+
cfg!(target_feature = "sse") || $crate::arch::detect::check_for(
5151
$crate::arch::detect::Feature::sse) };
5252
("sse2") => {
53-
$crate::arch::detect::check_for(
53+
cfg!(target_feature = "sse2") || $crate::arch::detect::check_for(
5454
$crate::arch::detect::Feature::sse2)
5555
};
5656
("sse3") => {
57-
$crate::arch::detect::check_for(
57+
cfg!(target_feature = "sse3") || $crate::arch::detect::check_for(
5858
$crate::arch::detect::Feature::sse3)
5959
};
6060
("ssse3") => {
61-
$crate::arch::detect::check_for(
61+
cfg!(target_feature = "ssse3") || $crate::arch::detect::check_for(
6262
$crate::arch::detect::Feature::ssse3)
6363
};
6464
("sse4.1") => {
65-
$crate::arch::detect::check_for(
65+
cfg!(target_feature = "sse4.1") || $crate::arch::detect::check_for(
6666
$crate::arch::detect::Feature::sse4_1)
6767
};
6868
("sse4.2") => {
69-
$crate::arch::detect::check_for(
69+
cfg!(target_feature = "sse4.2") || $crate::arch::detect::check_for(
7070
$crate::arch::detect::Feature::sse4_2)
7171
};
7272
("sse4a") => {
73-
$crate::arch::detect::check_for(
73+
cfg!(target_feature = "sse4a") || $crate::arch::detect::check_for(
7474
$crate::arch::detect::Feature::sse4a)
7575
};
7676
("avx") => {
77-
$crate::arch::detect::check_for(
77+
cfg!(target_feature = "avx") || $crate::arch::detect::check_for(
7878
$crate::arch::detect::Feature::avx)
7979
};
8080
("avx2") => {
81-
$crate::arch::detect::check_for(
81+
cfg!(target_feature = "avx2") || $crate::arch::detect::check_for(
8282
$crate::arch::detect::Feature::avx2)
8383
};
8484
("avx512f") => {
85-
$crate::arch::detect::check_for(
85+
cfg!(target_feature = "avx512f") || $crate::arch::detect::check_for(
8686
$crate::arch::detect::Feature::avx512f)
8787
};
8888
("avx512cd") => {
89-
$crate::arch::detect::check_for(
89+
cfg!(target_feature = "avx512cd") || $crate::arch::detect::check_for(
9090
$crate::arch::detect::Feature::avx512cd)
9191
};
9292
("avx512er") => {
93-
$crate::arch::detect::check_for(
93+
cfg!(target_feature = "avx512er") || $crate::arch::detect::check_for(
9494
$crate::arch::detect::Feature::avx512er)
9595
};
9696
("avx512pf") => {
97-
$crate::arch::detect::check_for(
97+
cfg!(target_feature = "avx512pf") || $crate::arch::detect::check_for(
9898
$crate::arch::detect::Feature::avx512pf)
9999
};
100100
("avx512bw") => {
101-
$crate::arch::detect::check_for(
101+
cfg!(target_feature = "avx512bw") || $crate::arch::detect::check_for(
102102
$crate::arch::detect::Feature::avx512bw)
103103
};
104104
("avx512dq") => {
105-
$crate::arch::detect::check_for(
105+
cfg!(target_feature = "avx512dq") || $crate::arch::detect::check_for(
106106
$crate::arch::detect::Feature::avx512dq)
107107
};
108108
("avx512vl") => {
109-
$crate::arch::detect::check_for(
109+
cfg!(target_Feature = "avx512vl") || $crate::arch::detect::check_for(
110110
$crate::arch::detect::Feature::avx512vl)
111111
};
112112
("avx512ifma") => {
113-
$crate::arch::detect::check_for(
113+
cfg!(target_feature = "avx512ifma") || $crate::arch::detect::check_for(
114114
$crate::arch::detect::Feature::avx512_ifma)
115115
};
116116
("avx512vbmi") => {
117-
$crate::arch::detect::check_for(
117+
cfg!(target_feature = "avx512vbmi") || $crate::arch::detect::check_for(
118118
$crate::arch::detect::Feature::avx512_vbmi)
119119
};
120120
("avx512vpopcntdq") => {
121-
$crate::arch::detect::check_for(
121+
cfg!(target_feature = "avx512vpopcntdq") || $crate::arch::detect::check_for(
122122
$crate::arch::detect::Feature::avx512_vpopcntdq)
123123
};
124124
("fma") => {
125-
$crate::arch::detect::check_for(
125+
cfg!(target_feature = "fma") || $crate::arch::detect::check_for(
126126
$crate::arch::detect::Feature::fma)
127127
};
128128
("bmi1") => {
129-
$crate::arch::detect::check_for(
129+
cfg!(target_feature = "bmi1") || $crate::arch::detect::check_for(
130130
$crate::arch::detect::Feature::bmi)
131131
};
132132
("bmi2") => {
133-
$crate::arch::detect::check_for(
133+
cfg!(target_feature = "bmi2") || $crate::arch::detect::check_for(
134134
$crate::arch::detect::Feature::bmi2)
135135
};
136136
("abm") => {
137-
$crate::arch::detect::check_for(
137+
cfg!(target_feature = "abm") || $crate::arch::detect::check_for(
138138
$crate::arch::detect::Feature::abm)
139139
};
140140
("lzcnt") => {
141-
$crate::arch::detect::check_for(
141+
cfg!(target_feature = "lzcnt") || $crate::arch::detect::check_for(
142142
$crate::arch::detect::Feature::abm)
143143
};
144144
("tbm") => {
145-
$crate::arch::detect::check_for(
145+
cfg!(target_feature = "tbm") || $crate::arch::detect::check_for(
146146
$crate::arch::detect::Feature::tbm)
147147
};
148148
("popcnt") => {
149-
$crate::arch::detect::check_for(
149+
cfg!(target_feature = "popcnt") || $crate::arch::detect::check_for(
150150
$crate::arch::detect::Feature::popcnt)
151151
};
152152
("fxsr") => {
153-
$crate::arch::detect::check_for(
153+
cfg!(target_feature = "fxsr") || $crate::arch::detect::check_for(
154154
$crate::arch::detect::Feature::fxsr)
155155
};
156156
("xsave") => {
157-
$crate::arch::detect::check_for(
157+
cfg!(target_feature = "xsave") || $crate::arch::detect::check_for(
158158
$crate::arch::detect::Feature::xsave)
159159
};
160160
("xsaveopt") => {
161-
$crate::arch::detect::check_for(
161+
cfg!(target_feature = "xsaveopt") || $crate::arch::detect::check_for(
162162
$crate::arch::detect::Feature::xsaveopt)
163163
};
164164
("xsaves") => {
165-
$crate::arch::detect::check_for(
165+
cfg!(target_feature = "xsaves") || $crate::arch::detect::check_for(
166166
$crate::arch::detect::Feature::xsaves)
167167
};
168168
("xsavec") => {
169-
$crate::arch::detect::check_for(
169+
cfg!(target_feature = "xsavec") || $crate::arch::detect::check_for(
170170
$crate::arch::detect::Feature::xsavec)
171171
};
172172
($t:tt) => {

0 commit comments

Comments
 (0)