Expand description
Fast bitwise Hamming distance using auto-vectorization with runtime SIMD detection on x86.
§Quick Start
use hamming_bitwise_fast::array;
let a: [u8; 128] = [0xFF; 128]; // 1024-bit vectors
let b: [u8; 128] = [0x00; 128];
// Single comparison
let distance = array::distance(&a, &b); // 1024
// One source vs many targets
let targets = vec![a, b];
let mut distances = vec![0u32; 2];
array::batch(&a, &targets, &mut distances);§Choosing an API
§Fixed-size arrays vs slices
If the vector size is known at compile time (e.g., 1024-bit embeddings are
[u8; 128]), use the array module for the best performance.
Use slice when sizes vary at runtime or are not known until program
execution.
§Single vs batch
Use array::batch or slice::batch when comparing one source against
many targets. Batch is the fastest approach for one-to-many comparisons.
§Platform Behavior
| Platform | Configuration | Behavior |
|---|---|---|
| x86/x86_64 | Default | Runtime CPU detection via multiversion (AVX-512/AVX2/SSE4.2) |
| x86/x86_64 | default-features = false | Baseline SSE2 only (slow) |
| ARM | Default | NEON is baseline; already optimized |
On x86, the default build automatically detects and uses the best available SIMD instructions at runtime:
cargo add hamming-bitwise-fastFor best single-call performance on x86, enable LTO so the compiler can auto-vectorize across the crate boundary:
[profile.release]
lto = trueFor maximum performance, also compile with -C target-cpu=native
(eliminates runtime dispatch overhead, at the cost of portability).
On ARM (including Apple Silicon), the default build is already fast.
§Feature Flags
multiversion_x86(enabled by default): Enables runtime CPU detection for optimal SIMD on x86 via themultiversioncrate. Disable withdefault-features = falseif you need zero dependencies or are targeting a known CPU with-C target-cpu=native.
Modules§
- array
- Fixed-size array APIs for bitwise Hamming distance.
- slice
- Variable-length slice APIs for bitwise Hamming distance.
Functions§
- hamming_
bitwise_ fast - Convenience alias for
slice::distancethat matches the crate name.