#[macro_export]
macro_rules! dispatch {
(
$(avx512 = $avx512_fn:expr,)?
$(avx2fma = $avx2fma_fn:expr,)?
$(avx2 = $avx2_fn:expr,)?
$(neon = $neon_fn:expr,)?
fallback = $fallback_fn:expr,
args = $args:tt
) => {{
$(
#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), feature = "nightly"))]
if $crate::dispatch::is_avx512_available() {
return $avx512_fn $args;
}
)?
$(
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
if $crate::dispatch::is_avx2_available() && $crate::dispatch::is_fma_available() {
return $avx2fma_fn $args;
}
)?
$(
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
if $crate::dispatch::is_avx2_available() {
return $avx2_fn $args;
}
)?
$(
#[cfg(target_arch = "aarch64")]
if $crate::dispatch::is_neon_available() {
return $neon_fn $args;
}
)?
$fallback_fn $args
}};
}
#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), feature = "nightly"))]
#[inline(always)]
pub fn is_avx512_available() -> bool {
if cfg!(target_feature = "avx512f") {
return true;
}
#[cfg(feature = "std")]
if std::arch::is_x86_feature_detected!("avx512f") {
return true;
}
false
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[inline(always)]
pub fn is_avx2_available() -> bool {
if cfg!(target_feature = "avx2") {
return true;
}
#[cfg(feature = "std")]
if std::arch::is_x86_feature_detected!("avx2") {
return true;
}
false
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[inline(always)]
pub fn is_fma_available() -> bool {
if cfg!(target_feature = "fma") {
return true;
}
#[cfg(feature = "std")]
if std::arch::is_x86_feature_detected!("fma") {
return true;
}
false
}
#[cfg(target_arch = "aarch64")]
#[inline(always)]
pub fn is_neon_available() -> bool {
if cfg!(target_feature = "neon") {
return true;
}
#[cfg(feature = "std")]
if std::arch::is_aarch64_feature_detected!("neon") {
return true;
}
false
}