Module simd

Module simd 

Source
Expand description

§SIMD-Accelerated Distance Functions

Optimized distance calculations using SIMD instructions. Falls back to scalar implementations when SIMD is not available.

§Supported Architectures

  • x86_64: AVX2, SSE4.1 (auto-detected at runtime)
  • aarch64: NEON (always available on Apple Silicon)
  • Fallback: Portable scalar implementation

§Performance

SIMD acceleration provides 2-8x speedup for distance calculations:

  • L2 (Euclidean): Process 8 floats per iteration (AVX) or 4 (SSE/NEON)
  • Dot product: Same vectorization approach
  • Cosine: Computed as 1 - dot(a,b) / (||a|| * ||b||)

Structs§

SimdCosine
SIMD-accelerated cosine distance
SimdDot
SIMD-accelerated dot product distance (for normalized vectors)
SimdInfo
Information about available SIMD features
SimdL2
SIMD-accelerated L2 (Euclidean squared) distance

Functions§

cosine_distance
Compute cosine distance with best available SIMD Returns 1 - cosine_similarity, so 0 = identical, 2 = opposite
dot_product
Compute dot product with best available SIMD
l2_squared
Compute L2 squared distance with best available SIMD
norm_squared
Compute squared norm with best available SIMD
simd_info
Returns information about SIMD capabilities