I want to compare two vectors of 16 bytes and get each corresponding index. A small example illustrating what I want:
fn get_matching_idx(arr1: &[u8], arr2: &[u8]) {
let vec1 = u8x16::load_aligned(arr1);
let vec2 = u8x16::load_aligned(arr2);
let matches = vec1.eq(vec2);
for i in 0..16 {
if matches.extract_unchecked(i) {
}
}
}
Ideally, I would just like to "Do something" for given indices, rather than checking each of them (there will be a small number of matches).
Is there a way to get matching indexes using intrinsics rather than iterating over the whole vector? For example, with gcc, I could use _mm_movemask_epi8 to pack the vector bit, and then repeat the applications __builtin_clzto get the index of the bits of the first set (which is more efficient for the sparse numbers that I would have). Alternatively, I could have a lookup table that did the right thing for every nibble in my bit integer (like the first answer here ).
Is there an equivalent of these instructions in rust?
I am compiling for an Intel x86-64 processor and cross-platform support is not a requirement.
. () , . - FFI .