Expand description
Zero-overhead SIMD function dispatch using OnceLock.
This module provides compile-time-like dispatch for SIMD functions by detecting CPU features once at startup and caching function pointers.
§Performance
- Zero branch overhead: Function pointer is resolved once, called directly thereafter
- No per-call checks: Eliminates
is_x86_feature_detected!in hot loops - Inlinable: Function pointers can be inlined by LLVM in some cases
§EPIC-C.2: TS-SIMD-002
Structs§
- Simd
Features - Information about available SIMD features.
Constants§
- CACHE_
LINE_ SIZE - Cache line size in bytes (standard for modern x86/ARM CPUs).
- PREFETCH_
DISTANCE_ 384D - Prefetch distance for 384-dimensional vectors.
- PREFETCH_
DISTANCE_ 768D - Prefetch distance for 768-dimensional vectors (3072 bytes).
Calculated at compile time:
768 * 4 / 64 = 48cache lines. - PREFETCH_
DISTANCE_ 1536D - Prefetch distance for 1536-dimensional vectors.
Functions§
- cosine_
dispatched - Computes cosine similarity using the best available SIMD implementation.
- cosine_
normalized_ dispatched - Computes cosine similarity for pre-normalized vectors.
- dot_
product_ dispatched - Computes dot product using the best available SIMD implementation.
- euclidean_
dispatched - Computes euclidean distance using the best available SIMD implementation.
- hamming_
dispatched - Computes Hamming distance using the best available implementation.
- prefetch_
distance - Calculates prefetch distance for a given dimension at compile time.
- simd_
features_ info - Returns information about which SIMD features are available.