Module simd_dispatch

Module simd_dispatch 

Source
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§

SimdFeatures
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 = 48 cache 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.