| 1 |
#![allow(dead_code)] |
| 2 |
#![allow(unreachable_code)] |
| 3 |
|
| 4 |
pub struct CpuFeatures; |
| 5 |
|
| 6 |
impl CpuFeatures { |
| 7 |
pub const NONE: usize = 0; |
| 8 |
pub const AVX2: usize = 1; |
| 9 |
} |
| 10 |
|
| 11 |
#[inline(always)] |
| 12 |
pub fn is_enabled_sse() -> bool { |
| 13 |
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] |
| 14 |
#[cfg(feature = "std")] |
| 15 |
return std::is_x86_feature_detected!("sse"); |
| 16 |
|
| 17 |
false |
| 18 |
} |
| 19 |
|
| 20 |
#[inline(always)] |
| 21 |
pub fn is_enabled_sse42() -> bool { |
| 22 |
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] |
| 23 |
#[cfg(feature = "std")] |
| 24 |
return std::is_x86_feature_detected!("sse4.2"); |
| 25 |
|
| 26 |
false |
| 27 |
} |
| 28 |
|
| 29 |
#[inline(always)] |
| 30 |
pub fn is_enabled_avx2_and_bmi2() -> bool { |
| 31 |
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] |
| 32 |
{ |
| 33 |
#[cfg(all( |
| 34 |
target_feature = "avx2", |
| 35 |
target_feature = "bmi1", |
| 36 |
target_feature = "bmi2" |
| 37 |
))] |
| 38 |
return true; |
| 39 |
|
| 40 |
#[cfg(feature = "std")] |
| 41 |
{ |
| 42 |
use std::sync::atomic::{AtomicU32, Ordering}; |
| 43 |
|
| 44 |
static CACHE: AtomicU32 = AtomicU32::new(2); |
| 45 |
|
| 46 |
return match CACHE.load(Ordering::Relaxed) { |
| 47 |
0 => false, |
| 48 |
1 => true, |
| 49 |
_ => { |
| 50 |
let detected = std::is_x86_feature_detected!("avx2") |
| 51 |
&& std::is_x86_feature_detected!("bmi1") |
| 52 |
&& std::is_x86_feature_detected!("bmi2"); |
| 53 |
CACHE.store(u32::from(detected), Ordering::Relaxed); |
| 54 |
detected |
| 55 |
} |
| 56 |
}; |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
false |
| 61 |
} |
| 62 |
|
| 63 |
#[inline(always)] |
| 64 |
pub fn is_enabled_avx512() -> bool { |
| 65 |
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] |
| 66 |
#[cfg(feature = "std")] |
| 67 |
return std::is_x86_feature_detected!("avx512f"); |
| 68 |
|
| 69 |
false |
| 70 |
} |
| 71 |
|
| 72 |
#[inline(always)] |
| 73 |
pub fn is_enabled_pclmulqdq() -> bool { |
| 74 |
#[cfg(target_arch = "x86_64")] |
| 75 |
#[cfg(feature = "std")] |
| 76 |
return std::is_x86_feature_detected!("pclmulqdq") && std::is_x86_feature_detected!("sse4.1"); |
| 77 |
|
| 78 |
false |
| 79 |
} |
| 80 |
|
| 81 |
#[inline(always)] |
| 82 |
pub fn is_enabled_neon() -> bool { |
| 83 |
#[cfg(target_arch = "aarch64")] |
| 84 |
{ |
| 85 |
#[cfg(target_feature = "neon")] |
| 86 |
return true; |
| 87 |
|
| 88 |
#[cfg(feature = "std")] |
| 89 |
return std::arch::is_aarch64_feature_detected!("neon"); |
| 90 |
} |
| 91 |
|
| 92 |
false |
| 93 |
} |
| 94 |
|
| 95 |
#[inline(always)] |
| 96 |
pub fn is_enabled_crc() -> bool { |
| 97 |
#[cfg(target_arch = "aarch64")] |
| 98 |
#[cfg(feature = "std")] |
| 99 |
return std::arch::is_aarch64_feature_detected!("crc"); |
| 100 |
|
| 101 |
false |
| 102 |
} |
| 103 |
|
| 104 |
// FIXME: Remove lsx feature guard once MSRV is 1.89.0 or higher |
| 105 |
#[inline(always)] |
| 106 |
pub fn is_enabled_lsx() -> bool { |
| 107 |
#[cfg(all(target_arch = "loongarch64", feature = "lsx"))] |
| 108 |
#[cfg(feature = "std")] |
| 109 |
return std::arch::is_loongarch_feature_detected!("lsx"); |
| 110 |
|
| 111 |
false |
| 112 |
} |
| 113 |
|
| 114 |
#[inline(always)] |
| 115 |
pub fn is_enabled_simd128() -> bool { |
| 116 |
#[cfg(target_arch = "wasm32")] |
| 117 |
return cfg!(target_feature = "simd128"); |
| 118 |
|
| 119 |
false |
| 120 |
} |