4 ms·
With AVX512, you can use masking and the vpopcntb instruction to avoid moving values between GPRs and vector registers until the very end: uint64_t count_occ
by 10000truths 3y ago
With AVX512, you can use masking and the vpopcntb instruction to avoid moving values between GPRs and vector registers until the very end:
uint64_t count_occurrences(const __m512i* vec_string, size_t num_vecs, char target) {
__m512i count_vec = _mm512_set1_epi64(0);
__m512i target_vec = _mm512_set1_epi8(target);
__m512i increment_vec = _mm512_set1_epi8(1);
for(size_t i = 0; i < num_vecs; ++i) {
__mmask64 cmp_mask = _mm512_cmpeq_epu8_mask(target_vec, vec_string[i]);
count_vec += _mm512_maskz_popcnt_epi8(cmp_mask, increment_vec);
}
return _mm512_reduce_add_epi64(count_vec);
}