diff options
| author | sayantn <sayantn05@gmail.com> | 2025-04-15 05:57:45 +0530 |
|---|---|---|
| committer | Amanieu d'Antras <amanieu@gmail.com> | 2025-04-20 21:39:39 +0000 |
| commit | cc6855e1e9aca84de7390406516ba606cf5aadc4 (patch) | |
| tree | e6c3fbbaec5bf09e6c4c7ed20b6f7af96f8f8764 /library/stdarch/crates/std_detect | |
| parent | f6fbd665a0a621bf9582c3c2b3b516dc871b2a3f (diff) | |
| download | rust-cc6855e1e9aca84de7390406516ba606cf5aadc4.tar.gz rust-cc6855e1e9aca84de7390406516ba606cf5aadc4.zip | |
Remove `cupid` dependency and `env-override-no-avx` CI run
Diffstat (limited to 'library/stdarch/crates/std_detect')
5 files changed, 3 insertions, 163 deletions
diff --git a/library/stdarch/crates/std_detect/Cargo.toml b/library/stdarch/crates/std_detect/Cargo.toml index 6f4f1c7b614..b6741100a72 100644 --- a/library/stdarch/crates/std_detect/Cargo.toml +++ b/library/stdarch/crates/std_detect/Cargo.toml @@ -31,14 +31,10 @@ alloc = { version = "1.0.0", optional = true, package = "rustc-std-workspace-all [target.'cfg(not(windows))'.dependencies] libc = { version = "0.2.0", optional = true, default-features = false } -[dev-dependencies] -cupid = "0.6.0" - [features] default = [ "std_detect_dlsym_getauxval", "std_detect_file_io" ] std_detect_file_io = [ "libc" ] std_detect_dlsym_getauxval = [ "libc" ] -std_detect_env_override = [ "libc" ] rustc-dep-of-std = [ "core", "compiler_builtins", diff --git a/library/stdarch/crates/std_detect/README.md b/library/stdarch/crates/std_detect/README.md index 009c10bebe7..091f5542e0e 100644 --- a/library/stdarch/crates/std_detect/README.md +++ b/library/stdarch/crates/std_detect/README.md @@ -52,8 +52,7 @@ crate from working on applications in which `std` is not available. * All `x86`/`x86_64` targets are supported on all platforms by querying the `cpuid` instruction directly for the features supported by the hardware and the operating system. `std_detect` assumes that the binary is an user-space - application. If you need raw support for querying `cpuid`, consider using the - [`cupid`](https://crates.io/crates/cupid) crate. + application. * Linux/Android: * `arm{32, 64}`, `mips{32,64}{,el}`, `powerpc{32,64}{,le}`, `loongarch64`, `s390x`: diff --git a/library/stdarch/crates/std_detect/src/detect/cache.rs b/library/stdarch/crates/std_detect/src/detect/cache.rs index 83bcedea612..67a8b1ea091 100644 --- a/library/stdarch/crates/std_detect/src/detect/cache.rs +++ b/library/stdarch/crates/std_detect/src/detect/cache.rs @@ -121,65 +121,12 @@ impl Cache { } } -cfg_if::cfg_if! { - if #[cfg(feature = "std_detect_env_override")] { - #[inline] - fn disable_features(disable: &[u8], value: &mut Initializer) { - if let Ok(disable) = core::str::from_utf8(disable) { - for v in disable.split(" ") { - let _ = super::Feature::from_str(v).map(|v| value.unset(v as u32)); - } - } - } - - #[inline] - 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)] { - use alloc::vec; - #[link(name = "kernel32")] - unsafe extern "system" { - fn GetEnvironmentVariableA(name: *const u8, buffer: *mut u8, size: u32) -> u32; - } - let len = unsafe { GetEnvironmentVariableA(RUST_STD_DETECT_UNSTABLE.as_ptr().cast::<u8>(), core::ptr::null_mut(), 0) }; - if len > 0 { - // +1 to include the null terminator. - let mut env = vec![0; len as usize + 1]; - let len = unsafe { GetEnvironmentVariableA(RUST_STD_DETECT_UNSTABLE.as_ptr().cast::<u8>(), env.as_mut_ptr(), len + 1) }; - if len > 0 { - disable_features(&env[..len as usize], &mut value); - } - } - } else { - let env = unsafe { - libc::getenv(RUST_STD_DETECT_UNSTABLE.as_ptr()) - }; - if !env.is_null() { - let len = unsafe { libc::strlen(env) }; - let env = unsafe { core::slice::from_raw_parts(env as *const u8, len) }; - disable_features(env, &mut value); - } - } - } - do_initialize(value); - value - } - } else { - #[inline] - fn initialize(value: Initializer) -> Initializer { - do_initialize(value); - value - } - } -} - #[inline] -fn do_initialize(value: Initializer) { +fn initialize(value: Initializer) -> Initializer { CACHE[0].initialize((value.0) as usize & Cache::MASK); CACHE[1].initialize((value.0 >> Cache::CAPACITY) as usize & Cache::MASK); CACHE[2].initialize((value.0 >> (2 * Cache::CAPACITY)) as usize & Cache::MASK); + value } // We only have to detect features once, and it's fairly costly, so hint to LLVM @@ -204,10 +151,6 @@ fn detect_and_initialize() -> Initializer { /// /// It uses the `Feature` variant to index into this variable as a bitset. If /// the bit is set, the feature is enabled, and otherwise it is disabled. -/// -/// If the feature `std_detect_env_override` is enabled looks for the env -/// variable `RUST_STD_DETECT_UNSTABLE` and uses its content to disable -/// Features that would had been otherwise detected. #[inline] pub(crate) fn test(bit: u32) -> bool { let (relative_bit, idx) = if bit < Cache::CAPACITY { diff --git a/library/stdarch/crates/std_detect/src/detect/macros.rs b/library/stdarch/crates/std_detect/src/detect/macros.rs index 9315b5ea313..64711c189a5 100644 --- a/library/stdarch/crates/std_detect/src/detect/macros.rs +++ b/library/stdarch/crates/std_detect/src/detect/macros.rs @@ -168,13 +168,6 @@ macro_rules! features { Feature::_last => unreachable!(), } } - #[cfg(feature = "std_detect_env_override")] - pub(crate) fn from_str(s: &str) -> Result<Feature, ()> { - match s { - $($feature_lit => Ok(Feature::$feature),)* - _ => Err(()) - } - } } /// Each function performs run-time feature detection for a single diff --git a/library/stdarch/crates/std_detect/tests/x86-specific.rs b/library/stdarch/crates/std_detect/tests/x86-specific.rs index f41f400c100..2b6a394910d 100644 --- a/library/stdarch/crates/std_detect/tests/x86-specific.rs +++ b/library/stdarch/crates/std_detect/tests/x86-specific.rs @@ -10,7 +10,6 @@ movrs_target_feature )] -extern crate cupid; #[macro_use] extern crate std_detect; @@ -109,96 +108,6 @@ fn dump() { println!("amx-movrs: {:?}", is_x86_feature_detected!("amx-movrs")); } -#[cfg(feature = "std_detect_env_override")] -#[test] -fn env_override_no_avx() { - if let Ok(disable) = std::env::var("RUST_STD_DETECT_UNSTABLE") { - let information = cupid::master().unwrap(); - for d in disable.split(" ") { - match d { - "avx" => { - if information.avx() { - assert_ne!(is_x86_feature_detected!("avx"), information.avx()) - } - } - "avx2" => { - if information.avx2() { - assert_ne!(is_x86_feature_detected!("avx2"), information.avx2()) - } - } - _ => {} - } - } - } -} - -#[test] -fn compare_with_cupid() { - let information = cupid::master().unwrap(); - assert_eq!(is_x86_feature_detected!("aes"), information.aesni()); - assert_eq!( - is_x86_feature_detected!("pclmulqdq"), - information.pclmulqdq() - ); - assert_eq!(is_x86_feature_detected!("rdrand"), information.rdrand()); - assert_eq!(is_x86_feature_detected!("rdseed"), information.rdseed()); - assert_eq!(is_x86_feature_detected!("tsc"), information.tsc()); - assert_eq!(is_x86_feature_detected!("sse"), information.sse()); - assert_eq!(is_x86_feature_detected!("sse2"), information.sse2()); - assert_eq!(is_x86_feature_detected!("sse3"), information.sse3()); - assert_eq!(is_x86_feature_detected!("ssse3"), information.ssse3()); - assert_eq!(is_x86_feature_detected!("sse4.1"), information.sse4_1()); - assert_eq!(is_x86_feature_detected!("sse4.2"), information.sse4_2()); - assert_eq!(is_x86_feature_detected!("sse4a"), information.sse4a()); - assert_eq!(is_x86_feature_detected!("sha"), information.sha()); - assert_eq!(is_x86_feature_detected!("f16c"), information.f16c()); - assert_eq!(is_x86_feature_detected!("avx"), information.avx()); - assert_eq!(is_x86_feature_detected!("avx2"), information.avx2()); - assert_eq!(is_x86_feature_detected!("avx512f"), information.avx512f()); - assert_eq!(is_x86_feature_detected!("avx512cd"), information.avx512cd()); - assert_eq!(is_x86_feature_detected!("avx512er"), information.avx512er()); - assert_eq!(is_x86_feature_detected!("avx512pf"), information.avx512pf()); - assert_eq!(is_x86_feature_detected!("avx512bw"), information.avx512bw()); - assert_eq!(is_x86_feature_detected!("avx512dq"), information.avx512dq()); - assert_eq!(is_x86_feature_detected!("avx512vl"), information.avx512vl()); - assert_eq!( - is_x86_feature_detected!("avx512ifma"), - information.avx512_ifma() - ); - assert_eq!( - is_x86_feature_detected!("avx512vbmi"), - information.avx512_vbmi() - ); - assert_eq!( - is_x86_feature_detected!("avx512vpopcntdq"), - information.avx512_vpopcntdq() - ); - assert_eq!(is_x86_feature_detected!("fma"), information.fma()); - assert_eq!(is_x86_feature_detected!("bmi1"), information.bmi1()); - assert_eq!(is_x86_feature_detected!("bmi2"), information.bmi2()); - assert_eq!(is_x86_feature_detected!("popcnt"), information.popcnt()); - assert_eq!(is_x86_feature_detected!("abm"), information.lzcnt()); - assert_eq!(is_x86_feature_detected!("tbm"), information.tbm()); - assert_eq!(is_x86_feature_detected!("lzcnt"), information.lzcnt()); - assert_eq!(is_x86_feature_detected!("xsave"), information.xsave()); - assert_eq!(is_x86_feature_detected!("xsaveopt"), information.xsaveopt()); - assert_eq!( - is_x86_feature_detected!("xsavec"), - information.xsavec_and_xrstor() - ); - assert_eq!( - is_x86_feature_detected!("xsaves"), - information.xsaves_xrstors_and_ia32_xss() - ); - assert_eq!( - is_x86_feature_detected!("cmpxchg16b"), - information.cmpxchg16b(), - ); - assert_eq!(is_x86_feature_detected!("adx"), information.adx(),); - assert_eq!(is_x86_feature_detected!("rtm"), information.rtm(),); - assert_eq!(is_x86_feature_detected!("movbe"), information.movbe(),); -} - #[test] #[allow(deprecated)] fn x86_deprecated() { |
