pub use super::kernels::Xxh3KernelId as KernelId;
use crate::platform::Caps;
#[cfg(any(test, feature = "diag"))]
pub const DEFAULT_BOUNDARIES: [usize; 3] = [64, 256, 4096];
#[derive(Clone, Copy, Debug)]
pub struct DispatchTable {
#[cfg(any(test, feature = "diag"))]
pub boundaries: [usize; 3],
#[cfg(any(test, feature = "diag"))]
pub xs: KernelId,
#[cfg(any(test, feature = "diag"))]
pub s: KernelId,
#[cfg(any(test, feature = "diag"))]
pub m: KernelId,
pub l: KernelId,
}
pub static DEFAULT_TABLE: DispatchTable = DispatchTable {
#[cfg(any(test, feature = "diag"))]
boundaries: DEFAULT_BOUNDARIES,
#[cfg(any(test, feature = "diag"))]
xs: KernelId::Portable,
#[cfg(any(test, feature = "diag"))]
s: KernelId::Portable,
#[cfg(any(test, feature = "diag"))]
m: KernelId::Portable,
l: KernelId::Portable,
};
#[cfg(target_arch = "x86_64")]
pub static AVX512_TABLE: DispatchTable = DispatchTable {
#[cfg(any(test, feature = "diag"))]
boundaries: DEFAULT_BOUNDARIES,
#[cfg(any(test, feature = "diag"))]
xs: KernelId::Avx512,
#[cfg(any(test, feature = "diag"))]
s: KernelId::Avx512,
#[cfg(any(test, feature = "diag"))]
m: KernelId::Avx512,
l: KernelId::Avx512,
};
#[cfg(target_arch = "x86_64")]
pub static AVX2_TABLE: DispatchTable = DispatchTable {
#[cfg(any(test, feature = "diag"))]
boundaries: DEFAULT_BOUNDARIES,
#[cfg(any(test, feature = "diag"))]
xs: KernelId::Avx2,
#[cfg(any(test, feature = "diag"))]
s: KernelId::Avx2,
#[cfg(any(test, feature = "diag"))]
m: KernelId::Avx2,
l: KernelId::Avx2,
};
#[cfg(target_arch = "aarch64")]
pub static NEON_TABLE: DispatchTable = DispatchTable {
#[cfg(any(test, feature = "diag"))]
boundaries: DEFAULT_BOUNDARIES,
#[cfg(any(test, feature = "diag"))]
xs: KernelId::Neon,
#[cfg(any(test, feature = "diag"))]
s: KernelId::Neon,
#[cfg(any(test, feature = "diag"))]
m: KernelId::Neon,
l: KernelId::Neon,
};
#[cfg(all(target_arch = "powerpc64", target_endian = "little"))]
pub static VSX_TABLE: DispatchTable = DispatchTable {
#[cfg(any(test, feature = "diag"))]
boundaries: DEFAULT_BOUNDARIES,
#[cfg(any(test, feature = "diag"))]
xs: KernelId::Vsx,
#[cfg(any(test, feature = "diag"))]
s: KernelId::Vsx,
#[cfg(any(test, feature = "diag"))]
m: KernelId::Vsx,
l: KernelId::Vsx,
};
#[cfg(target_arch = "s390x")]
pub static ZVECTOR_TABLE: DispatchTable = DispatchTable {
#[cfg(any(test, feature = "diag"))]
boundaries: DEFAULT_BOUNDARIES,
#[cfg(any(test, feature = "diag"))]
xs: KernelId::Vector,
#[cfg(any(test, feature = "diag"))]
s: KernelId::Vector,
#[cfg(any(test, feature = "diag"))]
m: KernelId::Vector,
l: KernelId::Vector,
};
#[cfg(target_arch = "riscv64")]
#[allow(dead_code)]
pub static RVV_TABLE: DispatchTable = DispatchTable {
#[cfg(any(test, feature = "diag"))]
boundaries: DEFAULT_BOUNDARIES,
#[cfg(any(test, feature = "diag"))]
xs: KernelId::Rvv,
#[cfg(any(test, feature = "diag"))]
s: KernelId::Rvv,
#[cfg(any(test, feature = "diag"))]
m: KernelId::Rvv,
l: KernelId::Rvv,
};
#[inline]
#[must_use]
pub fn select_runtime_table(caps: Caps) -> &'static DispatchTable {
let _ = caps;
#[cfg(target_arch = "x86_64")]
{
if caps.has(crate::platform::caps::x86::AVX512F) {
return &AVX512_TABLE;
}
if caps.has(crate::platform::caps::x86::AVX2) {
return &AVX2_TABLE;
}
}
#[cfg(target_arch = "aarch64")]
{
if caps.has(crate::platform::caps::aarch64::NEON) {
return &NEON_TABLE;
}
}
#[cfg(all(target_arch = "powerpc64", target_endian = "little"))]
{
if caps.has(crate::platform::caps::power::POWER8_VECTOR) {
return &VSX_TABLE;
}
}
#[cfg(target_arch = "s390x")]
{
if caps.has(crate::platform::caps::s390x::VECTOR) {
return &ZVECTOR_TABLE;
}
}
&DEFAULT_TABLE
}