Skip to main content

holographic_memory/core/
hardware.rs

1// Copyright 2024-2026 WritersLogic Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4use super::types::HardwareCapabilities;
5
6/// Detect CPU features without executing unsupported instructions.
7pub fn capabilities() -> HardwareCapabilities {
8    #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
9    let (avx2, avx512f) = (
10        std::is_x86_feature_detected!("avx2"),
11        std::is_x86_feature_detected!("avx512f"),
12    );
13    #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
14    let (avx2, avx512f) = (false, false);
15
16    #[cfg(target_arch = "aarch64")]
17    let neon = std::arch::is_aarch64_feature_detected!("neon");
18    #[cfg(target_arch = "arm")]
19    // Runtime detection on 32-bit ARM is unstable; report what the target was compiled with.
20    let neon = cfg!(target_feature = "neon");
21    #[cfg(not(any(target_arch = "aarch64", target_arch = "arm")))]
22    let neon = false;
23
24    HardwareCapabilities {
25        architecture: std::env::consts::ARCH.to_string(),
26        avx2,
27        avx512f,
28        neon,
29        // Sparse sorted u32 indices favor adaptive merge/galloping over dense SIMD.
30        sparse_intersection_kernel: "adaptive_merge_galloping".to_string(),
31    }
32}