What does AVX512 conflict detection do?

Author:Wojciech Muła
Added on:2016-10-23

AVX512CD

AVX512CD, or conflict detection, is a subset of AVX512 introducing following instructions:

The first two are not very interesting. Converting bit-mask into byte-mask saves in fact one move (vmovdqa32 with zero mask and a constant), it isn't too innovative. I can't find any real usage for lzcnt. Well, I wrote parallel popcount using this instruction (yes, 16 while-loops...), but it was just to show that I could.

In my opinion the most interesting are conflict detection instructions.

Conflict detection

A conflict means existence of duplicated values in a vector. The instructions works on integer vectors of either 32- or 64-bit values. The result is a vector of masks denoting positions of duplicates before given item.

For example:

input = [100, 100,   3, 100,   5, 100, 100,   3]
conflict result = [
         0b00000000,    // Note: the first element is always zero
         0b00000001,    // 100 is present on #0
         0b00000000,
         0b00000011,    // 100 is present on #0 and #1
         0b00000000,
         0b00001011,    // 100 is present on #0, #1, #3
         0b00011011,    // .. and #4
         0b00000100     // 3 is present on #2
]

Masks equal zero point to unique elements withing a vector. Thus, we can, for example, count unique elements or build a subvector of such values using a compress instruction (vpcompress{d|q}).

You can play with vpconflictd using a tiny program.