__m256i veca = _mm256_set1_epi16(a); // a is 16bit value you're looking for...
__m256i cmp = _mm256_cmpeq_epi16(veca, vecb); // vecb is the vector you want to search
uint32_t mask = _mm256_movemask_epi8(cmp); // cmp elements are 0 or 0xffff if no-match or match resp.
uint32_t index = 0; // mask is most significant bit of each byte in cmp
if (mask != 0) {
index = (30 - lzcnt32(mask))/2; // index is 0-15, 0 on right (higher address).
} else {
..no match.
}
1条答案
按热度按时间gmxoilav1#
从评论来看,似乎最好的方法是这样的...(未检测)