#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[allow(non_camel_case_types)]
pub enum MaxSimIsa {
Auto,
Scalar,
X86_64_V3,
X86_64_V4,
Neon,
Reference,
}
impl MaxSimIsa {
pub fn is_available(self) -> bool {
match self {
Self::Auto | Self::Scalar | Self::Reference => true,
#[cfg(target_arch = "x86_64")]
Self::X86_64_V3 => diskann_wide::arch::x86_64::V3::new_checked().is_some(),
#[cfg(target_arch = "x86_64")]
Self::X86_64_V4 => diskann_wide::arch::x86_64::V4::new_checked().is_some(),
#[cfg(not(target_arch = "x86_64"))]
Self::X86_64_V3 | Self::X86_64_V4 => false,
#[cfg(target_arch = "aarch64")]
Self::Neon => diskann_wide::arch::aarch64::Neon::new_checked().is_some(),
#[cfg(not(target_arch = "aarch64"))]
Self::Neon => false,
}
}
}
impl std::fmt::Display for MaxSimIsa {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self {
Self::Auto => "auto",
Self::Scalar => "scalar",
Self::X86_64_V3 => "x86-64-v3",
Self::X86_64_V4 => "x86-64-v4",
Self::Neon => "neon",
Self::Reference => "reference",
};
f.write_str(s)
}
}
#[derive(Debug, Clone, Copy)]
pub struct NotSupported {
pub isa: MaxSimIsa,
pub reason: &'static str,
}
impl std::fmt::Display for NotSupported {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{} not supported: {}", self.isa, self.reason)
}
}
impl std::error::Error for NotSupported {}