diff options
Diffstat (limited to 'library/std_detect/src/detect')
| -rw-r--r-- | library/std_detect/src/detect/arch/loongarch.rs | 3 | ||||
| -rw-r--r-- | library/std_detect/src/detect/arch/mod.rs | 36 | ||||
| -rw-r--r-- | library/std_detect/src/detect/cache.rs | 14 | ||||
| -rw-r--r-- | library/std_detect/src/detect/mod.rs | 36 | ||||
| -rw-r--r-- | library/std_detect/src/detect/os/freebsd/mod.rs | 13 | ||||
| -rw-r--r-- | library/std_detect/src/detect/os/linux/auxvec.rs | 9 | ||||
| -rw-r--r-- | library/std_detect/src/detect/os/linux/auxvec/tests.rs | 8 | ||||
| -rw-r--r-- | library/std_detect/src/detect/os/linux/loongarch.rs | 13 | ||||
| -rw-r--r-- | library/std_detect/src/detect/os/linux/mod.rs | 25 | 
9 files changed, 93 insertions, 64 deletions
| diff --git a/library/std_detect/src/detect/arch/loongarch.rs b/library/std_detect/src/detect/arch/loongarch.rs index 68fc600fa8e..d5a442fbbb8 100644 --- a/library/std_detect/src/detect/arch/loongarch.rs +++ b/library/std_detect/src/detect/arch/loongarch.rs @@ -8,6 +8,7 @@ features! { /// Checks if `loongarch` feature is enabled. /// Supported arguments are: /// + /// * `"32s"` /// * `"f"` /// * `"d"` /// * `"frecipe"` @@ -22,6 +23,8 @@ features! { /// * `"lvz"` /// * `"ual"` #[stable(feature = "stdarch_loongarch_feature", since = "1.89.0")] + @FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] _32s: "32s"; + /// 32S @FEATURE: #[stable(feature = "stdarch_loongarch_feature", since = "1.89.0")] f: "f"; /// F @FEATURE: #[stable(feature = "stdarch_loongarch_feature", since = "1.89.0")] d: "d"; diff --git a/library/std_detect/src/detect/arch/mod.rs b/library/std_detect/src/detect/arch/mod.rs index b0be554ed89..c066b9cc681 100644 --- a/library/std_detect/src/detect/arch/mod.rs +++ b/library/std_detect/src/detect/arch/mod.rs @@ -1,7 +1,5 @@ #![allow(dead_code)] -use cfg_if::cfg_if; - // Export the macros for all supported architectures. #[macro_use] mod x86; @@ -24,38 +22,48 @@ mod loongarch; #[macro_use] mod s390x; -cfg_if! { - if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { +cfg_select! { + any(target_arch = "x86", target_arch = "x86_64") => { #[stable(feature = "simd_x86", since = "1.27.0")] pub use x86::*; - } else if #[cfg(target_arch = "arm")] { + } + target_arch = "arm" => { #[unstable(feature = "stdarch_arm_feature_detection", issue = "111190")] pub use arm::*; - } else if #[cfg(any(target_arch = "aarch64", target_arch = "arm64ec"))] { + } + any(target_arch = "aarch64", target_arch = "arm64ec") => { #[stable(feature = "simd_aarch64", since = "1.60.0")] pub use aarch64::*; - } else if #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] { + } + any(target_arch = "riscv32", target_arch = "riscv64") => { #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] pub use riscv::*; - } else if #[cfg(target_arch = "powerpc")] { + } + target_arch = "powerpc" => { #[unstable(feature = "stdarch_powerpc_feature_detection", issue = "111191")] pub use powerpc::*; - } else if #[cfg(target_arch = "powerpc64")] { + } + target_arch = "powerpc64" => { #[unstable(feature = "stdarch_powerpc_feature_detection", issue = "111191")] pub use powerpc64::*; - } else if #[cfg(target_arch = "mips")] { + } + target_arch = "mips" => { #[unstable(feature = "stdarch_mips_feature_detection", issue = "111188")] pub use mips::*; - } else if #[cfg(target_arch = "mips64")] { + } + target_arch = "mips64" => { #[unstable(feature = "stdarch_mips_feature_detection", issue = "111188")] pub use mips64::*; - } else if #[cfg(any(target_arch = "loongarch32", target_arch = "loongarch64"))] { + } + any(target_arch = "loongarch32", target_arch = "loongarch64") => { #[stable(feature = "stdarch_loongarch_feature", since = "1.89.0")] pub use loongarch::*; - } else if #[cfg(target_arch = "s390x")] { + } + target_arch = "s390x" => { #[unstable(feature = "stdarch_s390x_feature_detection", issue = "135413")] pub use s390x::*; - } else { + } + _ => { // Unimplemented architecture: #[doc(hidden)] pub(crate) enum Feature { diff --git a/library/std_detect/src/detect/cache.rs b/library/std_detect/src/detect/cache.rs index 1a42e091463..c0c0b7b7f86 100644 --- a/library/std_detect/src/detect/cache.rs +++ b/library/std_detect/src/detect/cache.rs @@ -101,8 +101,8 @@ impl Cache { } } -cfg_if::cfg_if! { - if #[cfg(feature = "std_detect_env_override")] { +cfg_select! { + feature = "std_detect_env_override" => { #[inline] fn disable_features(disable: &[u8], value: &mut Initializer) { if let Ok(disable) = core::str::from_utf8(disable) { @@ -116,8 +116,8 @@ cfg_if::cfg_if! { fn initialize(mut value: Initializer) -> Initializer { use core::ffi::CStr; const RUST_STD_DETECT_UNSTABLE: &CStr = c"RUST_STD_DETECT_UNSTABLE"; - cfg_if::cfg_if! { - if #[cfg(windows)] { + cfg_select! { + windows => { use alloc::vec; #[link(name = "kernel32")] unsafe extern "system" { @@ -132,7 +132,8 @@ cfg_if::cfg_if! { disable_features(&env[..len as usize], &mut value); } } - } else { + } + _ => { let env = unsafe { libc::getenv(RUST_STD_DETECT_UNSTABLE.as_ptr()) }; @@ -146,7 +147,8 @@ cfg_if::cfg_if! { do_initialize(value); value } - } else { + } + _ => { #[inline] fn initialize(value: Initializer) -> Initializer { do_initialize(value); diff --git a/library/std_detect/src/detect/mod.rs b/library/std_detect/src/detect/mod.rs index f936a5a1345..2bc6e9a24db 100644 --- a/library/std_detect/src/detect/mod.rs +++ b/library/std_detect/src/detect/mod.rs @@ -17,8 +17,6 @@ //! due to security concerns (x86 is the big exception). These functions are //! implemented in the `os/{target_os}.rs` modules. -use cfg_if::cfg_if; - #[macro_use] mod macros; @@ -34,8 +32,8 @@ pub(crate) use self::arch::Feature; mod bit; mod cache; -cfg_if! { - if #[cfg(miri)] { +cfg_select! { + miri => { // When running under miri all target-features that are not enabled at // compile-time are reported as disabled at run-time. // @@ -43,35 +41,42 @@ cfg_if! { // this run-time detection logic is never called. #[path = "os/other.rs"] mod os; - } else if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { + } + any(target_arch = "x86", target_arch = "x86_64") => { // On x86/x86_64 no OS specific functionality is required. #[path = "os/x86.rs"] mod os; - } else if #[cfg(all(any(target_os = "linux", target_os = "android"), feature = "libc"))] { + } + all(any(target_os = "linux", target_os = "android"), feature = "libc") => { #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] #[path = "os/riscv.rs"] mod riscv; #[path = "os/linux/mod.rs"] mod os; - } else if #[cfg(all(target_os = "freebsd", feature = "libc"))] { + } + all(target_os = "freebsd", feature = "libc") => { #[cfg(target_arch = "aarch64")] #[path = "os/aarch64.rs"] mod aarch64; #[path = "os/freebsd/mod.rs"] mod os; - } else if #[cfg(all(target_os = "openbsd", target_arch = "aarch64", feature = "libc"))] { + } + all(target_os = "openbsd", target_arch = "aarch64", feature = "libc") => { #[allow(dead_code)] // we don't use code that calls the mrs instruction. #[path = "os/aarch64.rs"] mod aarch64; #[path = "os/openbsd/aarch64.rs"] mod os; - } else if #[cfg(all(target_os = "windows", any(target_arch = "aarch64", target_arch = "arm64ec")))] { + } + all(target_os = "windows", any(target_arch = "aarch64", target_arch = "arm64ec")) => { #[path = "os/windows/aarch64.rs"] mod os; - } else if #[cfg(all(target_vendor = "apple", target_arch = "aarch64", feature = "libc"))] { + } + all(target_vendor = "apple", target_arch = "aarch64", feature = "libc") => { #[path = "os/darwin/aarch64.rs"] mod os; - } else { + } + _ => { #[path = "os/other.rs"] mod os; } @@ -89,8 +94,8 @@ fn check_for(x: Feature) -> bool { /// is `true` if the feature is supported by the host and `false` otherwise. #[unstable(feature = "stdarch_internal", issue = "none")] pub fn features() -> impl Iterator<Item = (&'static str, bool)> { - cfg_if! { - if #[cfg(any( + cfg_select! { + any( target_arch = "x86", target_arch = "x86_64", target_arch = "arm", @@ -105,7 +110,7 @@ pub fn features() -> impl Iterator<Item = (&'static str, bool)> { target_arch = "loongarch32", target_arch = "loongarch64", target_arch = "s390x", - ))] { + ) => { (0_u8..Feature::_last as u8).map(|discriminant: u8| { #[allow(bindings_with_variant_name)] // RISC-V has Feature::f let f: Feature = unsafe { core::mem::transmute(discriminant) }; @@ -113,8 +118,7 @@ pub fn features() -> impl Iterator<Item = (&'static str, bool)> { let enabled: bool = check_for(f); (name, enabled) }) - } else { - None.into_iter() } + _ => None.into_iter(), } } diff --git a/library/std_detect/src/detect/os/freebsd/mod.rs b/library/std_detect/src/detect/os/freebsd/mod.rs index ade7fb6269d..7de9250e835 100644 --- a/library/std_detect/src/detect/os/freebsd/mod.rs +++ b/library/std_detect/src/detect/os/freebsd/mod.rs @@ -2,17 +2,20 @@ mod auxvec; -cfg_if::cfg_if! { - if #[cfg(target_arch = "aarch64")] { +cfg_select! { + target_arch = "aarch64" => { mod aarch64; pub(crate) use self::aarch64::detect_features; - } else if #[cfg(target_arch = "arm")] { + } + target_arch = "arm" => { mod arm; pub(crate) use self::arm::detect_features; - } else if #[cfg(target_arch = "powerpc64")] { + } + target_arch = "powerpc64" => { mod powerpc; pub(crate) use self::powerpc::detect_features; - } else { + } + _ => { use crate::detect::cache; /// Performs run-time feature detection. pub(crate) fn detect_features() -> cache::Initializer { diff --git a/library/std_detect/src/detect/os/linux/auxvec.rs b/library/std_detect/src/detect/os/linux/auxvec.rs index 443caaaa186..75e01bdc449 100644 --- a/library/std_detect/src/detect/os/linux/auxvec.rs +++ b/library/std_detect/src/detect/os/linux/auxvec.rs @@ -131,15 +131,15 @@ pub(crate) fn auxv() -> Result<AuxVec, ()> { /// `getauxval` function. If the function is not linked, this function return `Err`. fn getauxval(key: usize) -> Result<usize, ()> { type F = unsafe extern "C" fn(libc::c_ulong) -> libc::c_ulong; - cfg_if::cfg_if! { - if #[cfg(all( + cfg_select! { + all( feature = "std_detect_dlsym_getauxval", not(all( target_os = "linux", any(target_env = "gnu", target_env = "musl", target_env = "ohos"), )), not(target_os = "android"), - ))] { + ) => { let ffi_getauxval: F = unsafe { let ptr = libc::dlsym(libc::RTLD_DEFAULT, c"getauxval".as_ptr()); if ptr.is_null() { @@ -147,7 +147,8 @@ fn getauxval(key: usize) -> Result<usize, ()> { } core::mem::transmute(ptr) }; - } else { + } + _ => { let ffi_getauxval: F = libc::getauxval; } } diff --git a/library/std_detect/src/detect/os/linux/auxvec/tests.rs b/library/std_detect/src/detect/os/linux/auxvec/tests.rs index 536615fa272..631a3e5e9ef 100644 --- a/library/std_detect/src/detect/os/linux/auxvec/tests.rs +++ b/library/std_detect/src/detect/os/linux/auxvec/tests.rs @@ -42,8 +42,8 @@ fn auxv_dump() { } #[cfg(feature = "std_detect_file_io")] -cfg_if::cfg_if! { - if #[cfg(target_arch = "arm")] { +cfg_select! { + target_arch = "arm" => { // The tests below can be executed under qemu, where we do not have access to the test // files on disk, so we need to embed them with `include_bytes!`. #[test] @@ -62,7 +62,8 @@ cfg_if::cfg_if! { assert_eq!(v.hwcap, 126614527); assert_eq!(v.hwcap2, 0); } - } else if #[cfg(target_arch = "aarch64")] { + } + target_arch = "aarch64" => { #[cfg(target_endian = "little")] #[test] fn linux_artificial_aarch64() { @@ -81,6 +82,7 @@ cfg_if::cfg_if! { assert_eq!(v.hwcap2, 0); } } + _ => {} } #[test] diff --git a/library/std_detect/src/detect/os/linux/loongarch.rs b/library/std_detect/src/detect/os/linux/loongarch.rs index e97fda11d08..74415266f8b 100644 --- a/library/std_detect/src/detect/os/linux/loongarch.rs +++ b/library/std_detect/src/detect/os/linux/loongarch.rs @@ -17,22 +17,21 @@ pub(crate) fn detect_features() -> cache::Initializer { // The values are part of the platform-specific [cpucfg] // // [cpucfg]: LoongArch Reference Manual Volume 1: Basic Architecture v1.1 + let cpucfg1: usize; let cpucfg2: usize; - unsafe { - asm!( - "cpucfg {}, {}", - out(reg) cpucfg2, in(reg) 2, - options(pure, nomem, preserves_flags, nostack) - ); - } let cpucfg3: usize; unsafe { asm!( "cpucfg {}, {}", + "cpucfg {}, {}", + "cpucfg {}, {}", + out(reg) cpucfg1, in(reg) 1, + out(reg) cpucfg2, in(reg) 2, out(reg) cpucfg3, in(reg) 3, options(pure, nomem, preserves_flags, nostack) ); } + enable_feature(&mut value, Feature::_32s, bit::test(cpucfg1, 0) || bit::test(cpucfg1, 1)); enable_feature(&mut value, Feature::frecipe, bit::test(cpucfg2, 25)); enable_feature(&mut value, Feature::div32, bit::test(cpucfg2, 26)); enable_feature(&mut value, Feature::lam_bh, bit::test(cpucfg2, 27)); diff --git a/library/std_detect/src/detect/os/linux/mod.rs b/library/std_detect/src/detect/os/linux/mod.rs index 5ae2aaeab5b..5273c16c089 100644 --- a/library/std_detect/src/detect/os/linux/mod.rs +++ b/library/std_detect/src/detect/os/linux/mod.rs @@ -37,29 +37,36 @@ fn read_file(orig_path: &str) -> Result<Vec<u8>, alloc::string::String> { } } -cfg_if::cfg_if! { - if #[cfg(target_arch = "aarch64")] { +cfg_select! { + target_arch = "aarch64" => { mod aarch64; pub(crate) use self::aarch64::detect_features; - } else if #[cfg(target_arch = "arm")] { + } + target_arch = "arm" => { mod arm; pub(crate) use self::arm::detect_features; - } else if #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] { + } + any(target_arch = "riscv32", target_arch = "riscv64") => { mod riscv; pub(crate) use self::riscv::detect_features; - } else if #[cfg(any(target_arch = "mips", target_arch = "mips64"))] { + } + any(target_arch = "mips", target_arch = "mips64") => { mod mips; pub(crate) use self::mips::detect_features; - } else if #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] { + } + any(target_arch = "powerpc", target_arch = "powerpc64") => { mod powerpc; pub(crate) use self::powerpc::detect_features; - } else if #[cfg(any(target_arch = "loongarch32", target_arch = "loongarch64"))] { + } + any(target_arch = "loongarch32", target_arch = "loongarch64") => { mod loongarch; pub(crate) use self::loongarch::detect_features; - } else if #[cfg(target_arch = "s390x")] { + } + target_arch = "s390x" => { mod s390x; pub(crate) use self::s390x::detect_features; - } else { + } + _ => { use crate::detect::cache; /// Performs run-time feature detection. pub(crate) fn detect_features() -> cache::Initializer { | 
