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

Function avx2

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

Source from the content-addressed store, hash-verified

66#[cfg(target_arch = "x86_64")]
67#[target_feature(enable = "avx2")]
68unsafe fn avx2(a: &[u8], b: &[u8]) -> u32 {
69 let mut count = 0u32;
70 let n8 = a.len() / 8;
71 let ap = a.as_ptr() as *const u64;
72 let bp = b.as_ptr() as *const u64;
73 let mut i = 0usize;
74 while i + 4 <= n8 {
75 let x0 = (*ap.add(i)) ^ (*bp.add(i));
76 let x1 = (*ap.add(i + 1)) ^ (*bp.add(i + 1));
77 let x2 = (*ap.add(i + 2)) ^ (*bp.add(i + 2));
78 let x3 = (*ap.add(i + 3)) ^ (*bp.add(i + 3));
79 count += x0.count_ones() + x1.count_ones() + x2.count_ones() + x3.count_ones();
80 i += 4;
81 }
82 while i < n8 {
83 count += ((*ap.add(i)) ^ (*bp.add(i))).count_ones();
84 i += 1;
85 }
86 let tail_start = n8 * 8;
87 for j in tail_start..a.len() {
88 count += (*a.as_ptr().add(j) ^ *b.as_ptr().add(j)).count_ones();
89 }
90 count
91}
92
93#[cfg(target_arch = "x86_64")]
94fn avx512_trampoline(a: &[u8], b: &[u8]) -> u32 {

Callers 1

avx2_trampolineFunction · 0.85

Calls 4

count_onesMethod · 0.80
lenMethod · 0.45
as_ptrMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected