MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / scalar

Function scalar

nodedb-codec/src/vector_quant/hamming.rs:24–38  ·  view source on GitHub ↗
(a: &[u8], b: &[u8])

Source from the content-addressed store, hash-verified

22static DISPATCH: OnceLock<HammingFn> = OnceLock::new();
23
24fn scalar(a: &[u8], b: &[u8]) -> u32 {
25 let chunks = a.len() / 8;
26 let rem = a.len() % 8;
27 let mut count = 0u32;
28 for i in 0..chunks {
29 let av = u64::from_ne_bytes(a[i * 8..i * 8 + 8].try_into().unwrap_or([0u8; 8]));
30 let bv = u64::from_ne_bytes(b[i * 8..i * 8 + 8].try_into().unwrap_or([0u8; 8]));
31 count += (av ^ bv).count_ones();
32 }
33 let base = chunks * 8;
34 for i in 0..rem {
35 count += (a[base + i] ^ b[base + i]).count_ones();
36 }
37 count
38}
39
40#[cfg(target_arch = "x86_64")]
41#[target_feature(enable = "avx512f,avx512vpopcntdq")]

Callers

nothing calls this directly

Calls 2

count_onesMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected