Skip to content

Instantly share code, notes, and snippets.

@apage43
Created February 14, 2024 21:36
Show Gist options
  • Save apage43/8c1ad787127688cd326e63701d6b5661 to your computer and use it in GitHub Desktop.
Save apage43/8c1ad787127688cd326e63701d6b5661 to your computer and use it in GitHub Desktop.
#[cfg(all(target_arch = "x86_64", target_feature = "avx2"))]
unsafe fn hammcmp_256bit_avx2(mut a: &[u8], mut b: &[u8]) -> u32 {
use std::arch::x86_64::{*};
let mut dist = 0;
while a.len() >= 32 {
let av = _mm256_loadu_si256(a.as_ptr() as *const _);
let bv = _mm256_loadu_si256(b.as_ptr() as *const _);
let axorb = _mm256_xor_si256(av, bv);
dist += _popcnt64(_mm256_extract_epi64(axorb, 0));
dist += _popcnt64(_mm256_extract_epi64(axorb, 1));
dist += _popcnt64(_mm256_extract_epi64(axorb, 2));
dist += _popcnt64(_mm256_extract_epi64(axorb, 3));
a = &a[32..];
b = &b[32..];
}
debug_assert_eq!(a.len(), 0);
dist as u32
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment