Expand description
SIMD-accelerated distance computations for nearest-neighbor search.
§Strategy
Points are stored in Structure-of-Arrays (SoA) layout — three separate
f32 slices for X, Y, and Z — so that SIMD lanes map directly onto
multiple points at once.
AoS (cache-unfriendly for distance): [(x0,y0,z0), (x1,y1,z1), …]
SoA (SIMD-friendly): xs=[x0,x1,…] ys=[y0,y1,…] zs=[z0,z1,…]Given a query q = (qx, qy, qz) the squared distance to point i is:
d²ᵢ = (xᵢ−qx)² + (yᵢ−qy)² + (zᵢ−qz)²SIMD processes 4 (SSE2) or 8 (AVX2) distances per instruction cycle.
§Dispatch
has AVX2? → avx2_distances_squared (8-wide f32)
else SSE2? → sse2_distances_squared (4-wide f32, always present on x86-64)
else → scalar_distances_squared (portable fallback)The dispatch is resolved at runtime using is_x86_feature_detected!, so
the same binary runs correctly on all hardware while using the widest SIMD
available.
Structs§
- Simd
Brute Force Search - Brute-force nearest-neighbor search with SIMD-accelerated distance computation.
- SoaPoints
- Point cloud stored in Structure-of-Arrays format for SIMD-friendly access.
Functions§
- batch_
distances_ squared - Compute squared Euclidean distances from
queryto every point inpts. - scalar_
distances_ squared - Portable, vectorisation-friendly fallback (also the reference implementation).