Skip to main content

Module hamming

Module hamming 

Source
Expand description

Shared SIMD Hamming-distance kernel with runtime CPU-feature dispatch.

Used by 1-bit quantizers (bbq, rabitq) and any future binary code that needs to count differing bits between two equal-length packed-bit slices.

Dispatch order (resolved once via OnceLock):

  1. x86_64 + avx512f + avx512vpopcntdq → AVX-512 VPOPCNTDQ kernel
  2. x86_64 + avx2 → 64-bit popcnt unrolled 4×
  3. aarch64 → NEON vcntq_u8
  4. fallback → scalar 8-byte popcnt

Functions§

hamming_distance
Count the number of differing bits between two equal-length packed-bit slices, dispatching to the best available SIMD kernel at runtime.