Skip to content

Commit 6703f2a

Browse files
committed
Refactor architecture feature macros
1 parent 3195562 commit 6703f2a

File tree

10 files changed

+261
-690
lines changed

10 files changed

+261
-690
lines changed
Lines changed: 22 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,36 @@
11
//! Aarch64 run-time features.
22
3-
/// Checks if `aarch64` feature is enabled.
4-
#[macro_export]
5-
#[unstable(feature = "stdsimd", issue = "27731")]
6-
#[allow_internal_unstable(stdsimd_internal,stdsimd)]
7-
macro_rules! is_aarch64_feature_detected {
8-
("neon") => {
9-
// FIXME: this should be removed once we rename Aarch64 neon to asimd
10-
cfg!(target_feature = "neon") ||
11-
$crate::detect::check_for($crate::detect::Feature::asimd)
12-
};
13-
("asimd") => {
14-
cfg!(target_feature = "neon") ||
15-
$crate::detect::check_for($crate::detect::Feature::asimd)
16-
};
17-
("pmull") => {
18-
cfg!(target_feature = "pmull") ||
19-
$crate::detect::check_for($crate::detect::Feature::pmull)
20-
};
21-
("fp") => {
22-
cfg!(target_feature = "fp") ||
23-
$crate::detect::check_for($crate::detect::Feature::fp)
24-
};
25-
("fp16") => {
26-
cfg!(target_feature = "fp16") ||
27-
$crate::detect::check_for($crate::detect::Feature::fp16)
28-
};
29-
("sve") => {
30-
cfg!(target_feature = "sve") ||
31-
$crate::detect::check_for($crate::detect::Feature::sve)
32-
};
33-
("crc") => {
34-
cfg!(target_feature = "crc") ||
35-
$crate::detect::check_for($crate::detect::Feature::crc)
36-
};
37-
("crypto") => {
38-
cfg!(target_feature = "crypto") ||
39-
$crate::detect::check_for($crate::detect::Feature::crypto)
40-
};
41-
("lse") => {
42-
cfg!(target_feature = "lse") ||
43-
$crate::detect::check_for($crate::detect::Feature::lse)
44-
};
45-
("rdm") => {
46-
cfg!(target_feature = "rdm") ||
47-
$crate::detect::check_for($crate::detect::Feature::rdm)
48-
};
49-
("rcpc") => {
50-
cfg!(target_feature = "rcpc") ||
51-
$crate::detect::check_for($crate::detect::Feature::rcpc)
52-
};
53-
("dotprod") => {
54-
cfg!(target_feature = "dotprod") ||
55-
$crate::detect::check_for($crate::detect::Feature::dotprod)
56-
};
57-
("ras") => {
58-
compile_error!("\"ras\" feature cannot be detected at run-time")
59-
};
60-
("v8.1a") => {
61-
compile_error!("\"v8.1a\" feature cannot be detected at run-time")
62-
};
63-
("v8.2a") => {
64-
compile_error!("\"v8.2a\" feature cannot be detected at run-time")
65-
};
66-
("v8.3a") => {
67-
compile_error!("\"v8.3a\" feature cannot be detected at run-time")
68-
};
69-
($t:tt,) => {
70-
is_aarch64_feature_detected!($t);
71-
};
72-
($t:tt) => { compile_error!(concat!("unknown aarch64 target feature: ", $t)) };
73-
}
74-
75-
/// ARM Aarch64 CPU Feature enum. Each variant denotes a position in a bitset
76-
/// for a particular feature.
77-
///
78-
/// PLEASE: do not use this, it is an implementation detail subject to change.
79-
#[doc(hidden)]
80-
#[allow(non_camel_case_types)]
81-
#[derive(Copy, Clone)]
82-
#[repr(u8)]
83-
#[unstable(feature = "stdsimd_internal", issue = "0")]
84-
pub enum Feature {
3+
features! {
4+
@TARGET: aarch64;
5+
@MACRO_NAME: is_aarch64_feature_detected;
6+
@MACRO_ATTRS:
7+
/// Checks if `aarch64` feature is enabled.
8+
#[unstable(feature = "stdsimd", issue = "27731")]
9+
@BIND_FEATURE_NAME: "asimd"; "neon";
10+
@NO_RUNTIME_DETECTION: "ras";
11+
@NO_RUNTIME_DETECTION: "v8.1a";
12+
@NO_RUNTIME_DETECTION: "v8.2a";
13+
@NO_RUNTIME_DETECTION: "v8.3a";
14+
@FEATURE: asimd: "neon";
8515
/// ARM Advanced SIMD (ASIMD)
86-
asimd,
16+
@FEATURE: pmull: "pmull";
8717
/// Polynomial Multiply
88-
pmull,
18+
@FEATURE: fp: "fp";
8919
/// Floating point support
90-
fp,
20+
@FEATURE: fp16: "fp16";
9121
/// Half-float support.
92-
fp16,
22+
@FEATURE: sve: "sve";
9323
/// Scalable Vector Extension (SVE)
94-
sve,
24+
@FEATURE: crc: "crc";
9525
/// CRC32 (Cyclic Redundancy Check)
96-
crc,
26+
@FEATURE: crypto: "crypot";
9727
/// Crypto: AES + PMULL + SHA1 + SHA2
98-
crypto,
28+
@FEATURE: lse: "lse";
9929
/// Atomics (Large System Extension)
100-
lse,
30+
@FEATURE: rdm: "rdm";
10131
/// Rounding Double Multiply (ASIMDRDM)
102-
rdm,
32+
@FEATURE: rcpc: "rcpc";
10333
/// Release consistent Processor consistent (RcPc)
104-
rcpc,
34+
@FEATURE: dotprod: "dotprod";
10535
/// Vector Dot-Product (ASIMDDP)
106-
dotprod,
107-
108-
// Do not add variants after last:
109-
_last,
110-
}
111-
112-
impl Feature {
113-
pub fn to_str(self) -> &'static str {
114-
match self {
115-
Feature::asimd => "asimd",
116-
Feature::pmull => "pmull",
117-
Feature::fp => "fp",
118-
Feature::fp16 => "fp16",
119-
Feature::sve => "sve",
120-
Feature::crc => "crc",
121-
Feature::crypto => "crypto",
122-
Feature::lse => "lse",
123-
Feature::rdm => "rdm",
124-
Feature::rcpc => "rcpc",
125-
Feature::dotprod => "dotprod",
126-
Feature::_last => unreachable!(),
127-
}
128-
}
12936
}
Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,17 @@
11
//! Run-time feature detection on ARM Aarch32.
22
3-
/// Checks if `arm` feature is enabled.
4-
#[macro_export]
5-
#[unstable(feature = "stdsimd", issue = "27731")]
6-
#[allow_internal_unstable(stdsimd_internal,stdsimd)]
7-
macro_rules! is_arm_feature_detected {
8-
("neon") => {
9-
cfg!(target_feature = "neon") ||
10-
$crate::detect::check_for($crate::detect::Feature::neon)
11-
};
12-
("pmull") => {
13-
cfg!(target_feature = "pmull") ||
14-
$crate::detect::check_for($crate::detect::Feature::pmull)
15-
};
16-
("v7") => { compile_error!("\"v7\" feature cannot be detected at run-time") };
17-
("vfp2") => { compile_error!("\"vfp2\" feature cannot be detected at run-time") };
18-
("vfp3") => { compile_error!("\"vfp3\" feature cannot be detected at run-time") };
19-
("vfp4") => { compile_error!("\"vfp4\" feature cannot be detected at run-time") };
20-
($t:tt,) => {
21-
is_arm_feature_detected!($t);
22-
};
23-
($t:tt) => { compile_error!(concat!("unknown arm target feature: ", $t)) };
24-
}
25-
26-
/// ARM CPU Feature enum. Each variant denotes a position in a bitset for a
27-
/// particular feature.
28-
///
29-
/// PLEASE: do not use this, it is an implementation detail subject to change.
30-
#[doc(hidden)]
31-
#[allow(non_camel_case_types)]
32-
#[derive(Copy, Clone)]
33-
#[repr(u8)]
34-
#[unstable(feature = "stdsimd_internal", issue = "0")]
35-
pub enum Feature {
3+
features! {
4+
@TARGET: arm;
5+
@MACRO_NAME: is_arm_feature_detected;
6+
@MACRO_ATTRS:
7+
/// Checks if `arm` feature is enabled.
8+
#[unstable(feature = "stdsimd", issue = "27731")]
9+
@NO_RUNTIME_DETECTION: "v7";
10+
@NO_RUNTIME_DETECTION: "vfp2";
11+
@NO_RUNTIME_DETECTION: "vfp3";
12+
@NO_RUNTIME_DETECTION: "vfp4";
13+
@FEATURE: neon: "neon";
3614
/// ARM Advanced SIMD (NEON) - Aarch32
37-
neon,
15+
@FEATURE: pmull: "pmull";
3816
/// Polynomial Multiply
39-
pmull,
40-
41-
// Do not add variants after last:
42-
_last,
43-
}
44-
45-
impl Feature {
46-
pub fn to_str(self) -> &'static str {
47-
match self {
48-
Feature::neon => "neon",
49-
Feature::pmull => "pmull",
50-
Feature::_last => unreachable!(),
51-
}
52-
}
5317
}
Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,11 @@
11
//! Run-time feature detection on MIPS.
22
3-
/// Checks if `mips` feature is enabled.
4-
#[macro_export]
5-
#[unstable(feature = "stdsimd", issue = "27731")]
6-
#[allow_internal_unstable(stdsimd_internal,stdsimd)]
7-
macro_rules! is_mips_feature_detected {
8-
("msa") => {
9-
cfg!(target_feature = "msa") ||
10-
$crate::detect::check_for($crate::detect::Feature::msa)
11-
};
12-
($t:tt,) => {
13-
is_mips_feature_detected!($t);
14-
};
15-
($t:tt) => { compile_error!(concat!("unknown mips target feature: ", $t)) };
16-
}
17-
18-
/// MIPS CPU Feature enum. Each variant denotes a position in a bitset for a
19-
/// particular feature.
20-
///
21-
/// PLEASE: do not use this, it is an implementation detail subject to change.
22-
#[doc(hidden)]
23-
#[allow(non_camel_case_types)]
24-
#[derive(Copy, Clone)]
25-
#[repr(u8)]
26-
#[unstable(feature = "stdsimd_internal", issue = "0")]
27-
pub enum Feature {
3+
features! {
4+
@TARGET: mips;
5+
@MACRO_NAME: is_mips_feature_detected;
6+
@MACRO_ATTRS:
7+
/// Checks if `mips` feature is enabled.
8+
#[unstable(feature = "stdsimd", issue = "27731")]
9+
@FEATURE: msa: "msa";
2810
/// MIPS SIMD Architecture (MSA)
29-
msa,
30-
31-
// Do not add variants after last:
32-
_last,
33-
}
34-
35-
impl Feature {
36-
pub fn to_str(self) -> &'static str {
37-
match self {
38-
Feature::msa => "msa",
39-
Feature::_last => unreachable!(),
40-
}
41-
}
4211
}
Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,11 @@
11
//! Run-time feature detection on MIPS64.
22
3-
/// Checks if `mips64` feature is enabled.
4-
#[macro_export]
5-
#[unstable(feature = "stdsimd", issue = "27731")]
6-
#[allow_internal_unstable(stdsimd_internal,stdsimd)]
7-
macro_rules! is_mips64_feature_detected {
8-
("msa") => {
9-
cfg!(target_feature = "msa") ||
10-
$crate::detect::check_for($crate::detect::Feature::msa)
11-
};
12-
($t:tt,) => {
13-
is_mips64_feature_detected!($t);
14-
};
15-
($t:tt) => { compile_error!(concat!("unknown mips64 target feature: ", $t)) };
16-
}
17-
18-
/// MIPS64 CPU Feature enum. Each variant denotes a position in a bitset
19-
/// for a particular feature.
20-
///
21-
/// PLEASE: do not use this, it is an implementation detail subject to change.
22-
#[doc(hidden)]
23-
#[allow(non_camel_case_types)]
24-
#[derive(Copy, Clone)]
25-
#[repr(u8)]
26-
#[unstable(feature = "stdsimd_internal", issue = "0")]
27-
pub enum Feature {
3+
features! {
4+
@TARGET: mips64;
5+
@MACRO_NAME: is_mips64_feature_detected;
6+
@MACRO_ATTRS:
7+
/// Checks if `mips64` feature is enabled.
8+
#[unstable(feature = "stdsimd", issue = "27731")]
9+
@FEATURE: msa: "msa";
2810
/// MIPS SIMD Architecture (MSA)
29-
msa,
30-
31-
// Do not add variants after last:
32-
_last,
33-
}
34-
35-
impl Feature {
36-
pub fn to_str(self) -> &'static str {
37-
match self {
38-
Feature::msa => "msa",
39-
Feature::_last => unreachable!(),
40-
}
41-
}
4211
}
Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,15 @@
11
//! Run-time feature detection on PowerPC.
22
3-
/// Checks if `powerpc` feature is enabled.
4-
#[macro_export]
5-
#[unstable(feature = "stdsimd", issue = "27731")]
6-
#[allow_internal_unstable(stdsimd_internal,stdsimd)]
7-
macro_rules! is_powerpc_feature_detected {
8-
("altivec") => {
9-
cfg!(target_feature = "altivec") ||
10-
$crate::detect::check_for($crate::detect::Feature::altivec)
11-
};
12-
("vsx") => {
13-
cfg!(target_feature = "vsx") ||
14-
$crate::detect::check_for($crate::detect::Feature::vsx)
15-
};
16-
("power8") => {
17-
cfg!(target_feature = "power8") ||
18-
$crate::detect::check_for($crate::detect::Feature::power8)
19-
};
20-
($t:tt,) => {
21-
is_powerpc_feature_detected!($t);
22-
};
23-
($t:tt) => { compile_error!(concat!("unknown powerpc target feature: ", $t)) };
24-
}
25-
26-
27-
/// PowerPC CPU Feature enum. Each variant denotes a position in a bitset
28-
/// for a particular feature.
29-
///
30-
/// PLEASE: do not use this, it is an implementation detail subject to change.
31-
#[doc(hidden)]
32-
#[allow(non_camel_case_types)]
33-
#[derive(Copy, Clone)]
34-
#[repr(u8)]
35-
#[unstable(feature = "stdsimd_internal", issue = "0")]
36-
pub enum Feature {
3+
features! {
4+
@TARGET: powerpc;
5+
@MACRO_NAME: is_powerpc_feature_detected;
6+
@MACRO_ATTRS:
7+
/// Checks if `powerpc` feature is enabled.
8+
#[unstable(feature = "stdsimd", issue = "27731")]
9+
@FEATURE: altivec: "altivec";
3710
/// Altivec
38-
altivec,
11+
@FEATURE: vsx: "vsx";
3912
/// VSX
40-
vsx,
13+
@FEATURE: power8: "power8";
4114
/// Power8
42-
power8,
43-
44-
// Do not add variants after last:
45-
_last,
46-
}
47-
48-
impl Feature {
49-
pub fn to_str(self) -> &'static str {
50-
match self {
51-
Feature::altivec => "altivec",
52-
Feature::vsx => "vsx",
53-
Feature::power8 => "power8",
54-
Feature::_last => unreachable!(),
55-
}
56-
}
5715
}

0 commit comments

Comments
 (0)