Problem
Per-candidate rerank distance for 1-bit BBQ codecs allocates a Vec<f32> reconstruction per candidate (encode → dequantize → subtract → L2). For a 768-dim collection at oversample × ef candidates this is the dominant rerank cost and defeats SIMD.
Proposed solution
A fused kernel that computes dist² = Σq² − 2·scale·Σ(sign·q) + dim·scale² directly over packed sign bits, dispatched through a small function-pointer table chosen at runtime:
- AVX-512 (512-bit server: Ice Lake+, Zen 4/5) — 32 lanes,
_mm512_mask_blend_ps / masked ops
- AVX10/AVX-512VL (256-bit hybrid: Sierra/Clearwater Forest, Core Ultra) —
_mm256_mask_blend_ps, __mmask8
- AVX2+FMA (Haswell..Alder Lake, Zen 1-3) —
_mm256_blendv_ps
- NEON (aarch64) —
vbslq_f32, with a vtbl1_u8 LUT for bit expansion
- WASM SIMD128 —
v128_bitselect
- Portable scalar fallback (zero-allocation)
Bit order is MSB-first; byte.reverse_bits() maps dim k → lane k. Correctness gate: golden tests vs scalar across dims 8..512, tolerance 1e-4; criterion benches vs the current alloc path.
Engine / area
Vector (rerank codecs).
Alternatives & workarounds
Current code path is correct, just slower; scale by reducing oversample.
Before submitting
Problem
Per-candidate rerank distance for 1-bit BBQ codecs allocates a
Vec<f32>reconstruction per candidate (encode → dequantize → subtract → L2). For a 768-dim collection atoversample × efcandidates this is the dominant rerank cost and defeats SIMD.Proposed solution
A fused kernel that computes
dist² = Σq² − 2·scale·Σ(sign·q) + dim·scale²directly over packed sign bits, dispatched through a small function-pointer table chosen at runtime:_mm512_mask_blend_ps/ masked ops_mm256_mask_blend_ps,__mmask8_mm256_blendv_psvbslq_f32, with avtbl1_u8LUT for bit expansionv128_bitselectBit order is MSB-first;
byte.reverse_bits()maps dim k → lane k. Correctness gate: golden tests vs scalar across dims 8..512, tolerance 1e-4; criterion benches vs the current alloc path.Engine / area
Vector (rerank codecs).
Alternatives & workarounds
Current code path is correct, just slower; scale by reducing oversample.
Before submitting