Skip to main content

Module simd_native

Module simd_native 

Source
Expand description

Native SIMD intrinsics for maximum performance.

This module provides hand-tuned SIMD implementations using core::arch intrinsics for AVX-512, AVX2, and ARM NEON architectures.

§Module Structure

  • scalar — Scalar fallback implementations and fast-rsqrt helpers
  • tail_unroll — Remainder/tail handling macros for SIMD loops
  • prefetch — CPU cache prefetch utilities
  • reduction — Shared horizontal sum helpers for SIMD accumulators
  • x86_avx512 — AVX-512F kernel implementations (x86_64 only)
  • x86_avx2 — AVX2+FMA dot product and squared L2 kernels (x86_64 only)
  • x86_avx2_similarity — AVX2+FMA cosine, Hamming, Jaccard kernels (x86_64 only)
  • neon — ARM NEON kernel implementations (aarch64 only)
  • dispatch — Runtime SIMD level detection and dispatch wiring

§Performance (based on arXiv research)

  • AVX-512: True 16-wide f32 operations with masked remainder
  • AVX2: 8-wide f32 with FMA, multi-accumulator ILP
  • ARM NEON: Native 128-bit SIMD for Apple Silicon/ARM64
  • Prefetch: Software prefetching for cache optimization

§References

  • arXiv:2505.07621 “Bang for the Buck: Vector Search on Cloud CPUs”
  • arXiv:2502.18113 “Accelerating Graph Indexing for ANNS on Modern CPUs”

Re-exports§

pub use scalar::cosine_similarity_fast;
pub use scalar::fast_rsqrt;
pub use prefetch::calculate_prefetch_distance;
pub use prefetch::prefetch_vector;
pub use prefetch::prefetch_vector_multi_cache_line;
pub use prefetch::prefetch_vector_u64;
pub use prefetch::L2_CACHE_LINE_BYTES;

Modules§

adc
ADC (Asymmetric Distance Computation) for PQ-compressed vector search.
prefetch
CPU cache prefetch utilities for SIMD operations.
scalar
Scalar fallback implementations for SIMD distance metrics.

Structs§

DistanceEngine
Pre-resolved SIMD kernels for repeated distance operations at a fixed dimension.

Enums§

SimdLevel
SIMD capability level detected at runtime.

Functions§

batch_cosine_native
Batch cosine similarity with cross-platform multi-level prefetch hints.
batch_dot_product_native
Batch dot product with cross-platform multi-level prefetch hints.
batch_euclidean_native
Batch euclidean distance with cross-platform multi-level prefetch hints.
batch_hamming_native
Batch Hamming distance with cross-platform multi-level prefetch hints.
batch_jaccard_native
Batch Jaccard similarity with cross-platform multi-level prefetch hints.
batch_squared_l2_native
Batch squared L2 distance with cross-platform multi-level prefetch hints.
cosine_normalized_native
Cosine for pre-normalized vectors with runtime SIMD dispatch.
cosine_similarity_native
Cosine similarity with runtime SIMD dispatch.
dot_product_native
Dot product with runtime SIMD dispatch.
euclidean_native
Euclidean distance with runtime SIMD dispatch.
hamming_binary_native
Binary Hamming distance with runtime SIMD dispatch.
hamming_distance_native
Hamming distance with runtime SIMD dispatch.
jaccard_similarity_native
Jaccard similarity with runtime SIMD dispatch.
norm_native
L2 norm with runtime SIMD dispatch.
normalize_inplace_native
In-place normalization with runtime SIMD dispatch.
simd_level
Returns the cached SIMD level for the current process.
squared_l2_native
Squared L2 distance with runtime SIMD dispatch.
warmup_simd_cache
Warms up runtime SIMD dispatch cache and CPU caches for common dimensions.