Skip to content

Add std_detect::detect::features() API that returns iterator of target-features and reject unstable features in feature-detection macros #739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/azure-install-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ steps:
- script: |
@echo on
if not defined TOOLCHAIN set TOOLCHAIN=nightly
rustup update %TOOLCHAIN%-%TARGET%
rustup update --no-self-update %TOOLCHAIN%-%TARGET%
rustup default %TOOLCHAIN%-%TARGET%
displayName: Install rust (windows)
condition: eq( variables['Agent.OS'], 'Windows_NT' )
Expand Down
6 changes: 3 additions & 3 deletions crates/core_arch/src/mips/msa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13531,7 +13531,7 @@ mod tests {
#[simd_test(enable = "msa")]
unsafe fn test_msa_frint_w() {
#[rustfmt::skip]
let a = f32x4::new(2.6, -2.7, 1.3, -1.7);;
let a = f32x4::new(2.6, -2.7, 1.3, -1.7);
#[rustfmt::skip]
let r = f32x4::new(3.0, -3.0, 1.0, -2.0);

Expand All @@ -13551,7 +13551,7 @@ mod tests {
#[simd_test(enable = "msa")]
unsafe fn test_msa_frcp_w() {
#[rustfmt::skip]
let a = f32x4::new(2.6, -2.7, 1.3, -1.7);;
let a = f32x4::new(2.6, -2.7, 1.3, -1.7);
#[rustfmt::skip]
let r = f32x4::new(
0.3846154, -0.37037036,
Expand All @@ -13574,7 +13574,7 @@ mod tests {
#[simd_test(enable = "msa")]
unsafe fn test_msa_frsqrt_w() {
#[rustfmt::skip]
let a = f32x4::new(2.6, 2.7, 1.3, 1.7);;
let a = f32x4::new(2.6, 2.7, 1.3, 1.7);
#[rustfmt::skip]
let r = f32x4::new(
0.6201737, 0.6085806,
Expand Down
114 changes: 22 additions & 92 deletions crates/std_detect/src/detect/arch/aarch64.rs
Original file line number Diff line number Diff line change
@@ -1,106 +1,36 @@
//! Aarch64 run-time features.

/// Checks if `aarch64` feature is enabled.
#[macro_export]
#[unstable(feature = "stdsimd", issue = "27731")]
#[allow_internal_unstable(stdsimd_internal,stdsimd)]
macro_rules! is_aarch64_feature_detected {
("neon") => {
// FIXME: this should be removed once we rename Aarch64 neon to asimd
cfg!(target_feature = "neon") ||
$crate::detect::check_for($crate::detect::Feature::asimd)
};
("asimd") => {
cfg!(target_feature = "neon") ||
$crate::detect::check_for($crate::detect::Feature::asimd)
};
("pmull") => {
cfg!(target_feature = "pmull") ||
$crate::detect::check_for($crate::detect::Feature::pmull)
};
("fp") => {
cfg!(target_feature = "fp") ||
$crate::detect::check_for($crate::detect::Feature::fp)
};
("fp16") => {
cfg!(target_feature = "fp16") ||
$crate::detect::check_for($crate::detect::Feature::fp16)
};
("sve") => {
cfg!(target_feature = "sve") ||
$crate::detect::check_for($crate::detect::Feature::sve)
};
("crc") => {
cfg!(target_feature = "crc") ||
$crate::detect::check_for($crate::detect::Feature::crc)
};
("crypto") => {
cfg!(target_feature = "crypto") ||
$crate::detect::check_for($crate::detect::Feature::crypto)
};
("lse") => {
cfg!(target_feature = "lse") ||
$crate::detect::check_for($crate::detect::Feature::lse)
};
("rdm") => {
cfg!(target_feature = "rdm") ||
$crate::detect::check_for($crate::detect::Feature::rdm)
};
("rcpc") => {
cfg!(target_feature = "rcpc") ||
$crate::detect::check_for($crate::detect::Feature::rcpc)
};
("dotprod") => {
cfg!(target_feature = "dotprod") ||
$crate::detect::check_for($crate::detect::Feature::dotprod)
};
("ras") => {
compile_error!("\"ras\" feature cannot be detected at run-time")
};
("v8.1a") => {
compile_error!("\"v8.1a\" feature cannot be detected at run-time")
};
("v8.2a") => {
compile_error!("\"v8.2a\" feature cannot be detected at run-time")
};
("v8.3a") => {
compile_error!("\"v8.3a\" feature cannot be detected at run-time")
};
($t:tt,) => {
is_aarch64_feature_detected!($t);
};
($t:tt) => { compile_error!(concat!("unknown aarch64 target feature: ", $t)) };
}

/// ARM Aarch64 CPU Feature enum. Each variant denotes a position in a bitset
/// for a particular feature.
///
/// PLEASE: do not use this, it is an implementation detail subject to change.
#[doc(hidden)]
#[allow(non_camel_case_types)]
#[repr(u8)]
#[unstable(feature = "stdsimd_internal", issue = "0")]
pub enum Feature {
features! {
@TARGET: aarch64;
@MACRO_NAME: is_aarch64_feature_detected;
@MACRO_ATTRS:
/// Checks if `aarch64` feature is enabled.
#[unstable(feature = "stdsimd", issue = "27731")]
@BIND_FEATURE_NAME: "asimd"; "neon";
@NO_RUNTIME_DETECTION: "ras";
@NO_RUNTIME_DETECTION: "v8.1a";
@NO_RUNTIME_DETECTION: "v8.2a";
@NO_RUNTIME_DETECTION: "v8.3a";
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] asimd: "neon";
/// ARM Advanced SIMD (ASIMD)
asimd,
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] pmull: "pmull";
/// Polynomial Multiply
pmull,
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] fp: "fp";
/// Floating point support
fp,
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] fp16: "fp16";
/// Half-float support.
fp16,
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] sve: "sve";
/// Scalable Vector Extension (SVE)
sve,
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] crc: "crc";
/// CRC32 (Cyclic Redundancy Check)
crc,
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] crypto: "crypto";
/// Crypto: AES + PMULL + SHA1 + SHA2
crypto,
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] lse: "lse";
/// Atomics (Large System Extension)
lse,
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] rdm: "rdm";
/// Rounding Double Multiply (ASIMDRDM)
rdm,
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] rcpc: "rcpc";
/// Release consistent Processor consistent (RcPc)
rcpc,
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] dotprod: "dotprod";
/// Vector Dot-Product (ASIMDDP)
dotprod,
}
46 changes: 12 additions & 34 deletions crates/std_detect/src/detect/arch/arm.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,17 @@
//! Run-time feature detection on ARM Aarch32.

/// Checks if `arm` feature is enabled.
#[macro_export]
#[unstable(feature = "stdsimd", issue = "27731")]
#[allow_internal_unstable(stdsimd_internal,stdsimd)]
macro_rules! is_arm_feature_detected {
("neon") => {
cfg!(target_feature = "neon") ||
$crate::detect::check_for($crate::detect::Feature::neon)
};
("pmull") => {
cfg!(target_feature = "pmull") ||
$crate::detect::check_for($crate::detect::Feature::pmull)
};
("v7") => { compile_error!("\"v7\" feature cannot be detected at run-time") };
("vfp2") => { compile_error!("\"vfp2\" feature cannot be detected at run-time") };
("vfp3") => { compile_error!("\"vfp3\" feature cannot be detected at run-time") };
("vfp4") => { compile_error!("\"vfp4\" feature cannot be detected at run-time") };
($t:tt,) => {
is_arm_feature_detected!($t);
};
($t:tt) => { compile_error!(concat!("unknown arm target feature: ", $t)) };
}

/// ARM CPU Feature enum. Each variant denotes a position in a bitset for a
/// particular feature.
///
/// PLEASE: do not use this, it is an implementation detail subject to change.
#[doc(hidden)]
#[allow(non_camel_case_types)]
#[repr(u8)]
#[unstable(feature = "stdsimd_internal", issue = "0")]
pub enum Feature {
features! {
@TARGET: arm;
@MACRO_NAME: is_arm_feature_detected;
@MACRO_ATTRS:
/// Checks if `arm` feature is enabled.
#[unstable(feature = "stdsimd", issue = "27731")]
@NO_RUNTIME_DETECTION: "v7";
@NO_RUNTIME_DETECTION: "vfp2";
@NO_RUNTIME_DETECTION: "vfp3";
@NO_RUNTIME_DETECTION: "vfp4";
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] neon: "neon";
/// ARM Advanced SIMD (NEON) - Aarch32
neon,
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] pmull: "pmull";
/// Polynomial Multiply
pmull,
}
32 changes: 7 additions & 25 deletions crates/std_detect/src/detect/arch/mips.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
//! Run-time feature detection on MIPS.

/// Checks if `mips` feature is enabled.
#[macro_export]
#[unstable(feature = "stdsimd", issue = "27731")]
#[allow_internal_unstable(stdsimd_internal,stdsimd)]
macro_rules! is_mips_feature_detected {
("msa") => {
cfg!(target_feature = "msa") ||
$crate::detect::check_for($crate::detect::Feature::msa)
};
($t:tt,) => {
is_mips_feature_detected!($t);
};
($t:tt) => { compile_error!(concat!("unknown mips target feature: ", $t)) };
}

/// MIPS CPU Feature enum. Each variant denotes a position in a bitset for a
/// particular feature.
///
/// PLEASE: do not use this, it is an implementation detail subject to change.
#[doc(hidden)]
#[allow(non_camel_case_types)]
#[repr(u8)]
#[unstable(feature = "stdsimd_internal", issue = "0")]
pub enum Feature {
features! {
@TARGET: mips;
@MACRO_NAME: is_mips_feature_detected;
@MACRO_ATTRS:
/// Checks if `mips` feature is enabled.
#[unstable(feature = "stdsimd", issue = "27731")]
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] msa: "msa";
/// MIPS SIMD Architecture (MSA)
msa,
}
32 changes: 7 additions & 25 deletions crates/std_detect/src/detect/arch/mips64.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
//! Run-time feature detection on MIPS64.

/// Checks if `mips64` feature is enabled.
#[macro_export]
#[unstable(feature = "stdsimd", issue = "27731")]
#[allow_internal_unstable(stdsimd_internal,stdsimd)]
macro_rules! is_mips64_feature_detected {
("msa") => {
cfg!(target_feature = "msa") ||
$crate::detect::check_for($crate::detect::Feature::msa)
};
($t:tt,) => {
is_mips64_feature_detected!($t);
};
($t:tt) => { compile_error!(concat!("unknown mips64 target feature: ", $t)) };
}

/// MIPS64 CPU Feature enum. Each variant denotes a position in a bitset
/// for a particular feature.
///
/// PLEASE: do not use this, it is an implementation detail subject to change.
#[doc(hidden)]
#[allow(non_camel_case_types)]
#[repr(u8)]
#[unstable(feature = "stdsimd_internal", issue = "0")]
pub enum Feature {
features! {
@TARGET: mips64;
@MACRO_NAME: is_mips64_feature_detected;
@MACRO_ATTRS:
/// Checks if `mips64` feature is enabled.
#[unstable(feature = "stdsimd", issue = "27731")]
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] msa: "msa";
/// MIPS SIMD Architecture (MSA)
msa,
}
45 changes: 9 additions & 36 deletions crates/std_detect/src/detect/arch/powerpc.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,15 @@
//! Run-time feature detection on PowerPC.

/// Checks if `powerpc` feature is enabled.
#[macro_export]
#[unstable(feature = "stdsimd", issue = "27731")]
#[allow_internal_unstable(stdsimd_internal,stdsimd)]
macro_rules! is_powerpc_feature_detected {
("altivec") => {
cfg!(target_feature = "altivec") ||
$crate::detect::check_for($crate::detect::Feature::altivec)
};
("vsx") => {
cfg!(target_feature = "vsx") ||
$crate::detect::check_for($crate::detect::Feature::vsx)
};
("power8") => {
cfg!(target_feature = "power8") ||
$crate::detect::check_for($crate::detect::Feature::power8)
};
($t:tt,) => {
is_powerpc_feature_detected!($t);
};
($t:tt) => { compile_error!(concat!("unknown powerpc target feature: ", $t)) };
}


/// PowerPC CPU Feature enum. Each variant denotes a position in a bitset
/// for a particular feature.
///
/// PLEASE: do not use this, it is an implementation detail subject to change.
#[doc(hidden)]
#[allow(non_camel_case_types)]
#[repr(u8)]
#[unstable(feature = "stdsimd_internal", issue = "0")]
pub enum Feature {
features! {
@TARGET: powerpc;
@MACRO_NAME: is_powerpc_feature_detected;
@MACRO_ATTRS:
/// Checks if `powerpc` feature is enabled.
#[unstable(feature = "stdsimd", issue = "27731")]
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] altivec: "altivec";
/// Altivec
altivec,
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] vsx: "vsx";
/// VSX
vsx,
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] power8: "power8";
/// Power8
power8,
}
45 changes: 9 additions & 36 deletions crates/std_detect/src/detect/arch/powerpc64.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,15 @@
//! Run-time feature detection on PowerPC64.

/// Checks if `powerpc64` feature is enabled.
#[macro_export]
#[unstable(feature = "stdsimd", issue = "27731")]
#[allow_internal_unstable(stdsimd_internal,stdsimd)]
macro_rules! is_powerpc64_feature_detected {
("altivec") => {
cfg!(target_feature = "altivec") ||
$crate::detect::check_for($crate::detect::Feature::altivec)
};
("vsx") => {
cfg!(target_feature = "vsx") ||
$crate::detect::check_for($crate::detect::Feature::vsx)
};
("power8") => {
cfg!(target_feature = "power8") ||
$crate::detect::check_for($crate::detect::Feature::power8)
};
($t:tt,) => {
is_powerpc64_feature_detected!($t);
};
($t:tt) => { compile_error!(concat!("unknown powerpc64 target feature: ", $t)) };
}


/// PowerPC64 CPU Feature enum. Each variant denotes a position in a bitset
/// for a particular feature.
///
/// PLEASE: do not use this, it is an implementation detail subject to change.
#[doc(hidden)]
#[allow(non_camel_case_types)]
#[repr(u8)]
#[unstable(feature = "stdsimd_internal", issue = "0")]
pub enum Feature {
features! {
@TARGET: powerpc64;
@MACRO_NAME: is_powerpc64_feature_detected;
@MACRO_ATTRS:
/// Checks if `powerpc` feature is enabled.
#[unstable(feature = "stdsimd", issue = "27731")]
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] altivec: "altivec";
/// Altivec
altivec,
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] vsx: "vsx";
/// VSX
vsx,
@FEATURE: #[unstable(feature = "stdsimd", issue = "27731")] power8: "power8";
/// Power8
power8,
}
Loading