#![allow(unused_imports)]
#![allow(dead_code)]
#[cfg(feature = "simd")]
pub mod wide;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub mod x86;
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
pub mod arm;
#[cfg(target_arch = "wasm32")]
pub mod wasm;
pub struct SimdDetector {
has_sse2: bool,
has_sse4_1: bool,
has_avx: bool,
has_avx2: bool,
has_avx512: bool,
has_neon: bool,
has_wasm_simd128: bool,
}
impl Default for SimdDetector {
fn default() -> Self {
Self::new()
}
}
impl SimdDetector {
pub fn new() -> Self {
Self {
#[cfg(target_arch = "x86_64")]
has_sse2: std::arch::is_x86_feature_detected!("sse2"),
#[cfg(target_arch = "x86")]
has_sse2: std::arch::is_x86_feature_detected!("sse2"),
#[cfg(target_arch = "x86_64")]
has_sse4_1: std::arch::is_x86_feature_detected!("sse4.1"),
#[cfg(target_arch = "x86")]
has_sse4_1: std::arch::is_x86_feature_detected!("sse4.1"),
#[cfg(target_arch = "x86_64")]
has_avx: std::arch::is_x86_feature_detected!("avx"),
#[cfg(target_arch = "x86")]
has_avx: std::arch::is_x86_feature_detected!("avx"),
#[cfg(target_arch = "x86_64")]
has_avx2: std::arch::is_x86_feature_detected!("avx2"),
#[cfg(target_arch = "x86")]
has_avx2: std::arch::is_x86_feature_detected!("avx2"),
#[cfg(target_arch = "x86_64")]
has_avx512: std::arch::is_x86_feature_detected!("avx512f"),
#[cfg(target_arch = "x86")]
has_avx512: std::arch::is_x86_feature_detected!("avx512f"),
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
has_sse2: false,
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
has_sse4_1: false,
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
has_avx: false,
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
has_avx2: false,
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
has_avx512: false,
#[cfg(target_arch = "aarch64")]
has_neon: std::arch::is_aarch64_feature_detected!("neon"),
#[cfg(not(target_arch = "aarch64"))]
has_neon: false,
#[cfg(target_arch = "wasm32")]
has_wasm_simd128: true,
#[cfg(not(target_arch = "wasm32"))]
has_wasm_simd128: false,
}
}
pub fn recommended_simd_width<T: crate::Transcendental>() -> usize {
let det = Self::new();
if det.has_avx {
return 8;
}
if det.has_sse2 || det.has_neon || det.has_wasm_simd128 {
return 4;
}
1
}
}
#[cfg(feature = "simd")]
pub use wide::*;