Is there a fast way to count the number of unique elements in a simd vector (AVX and any SSE) without converting to array? I want to use it in a specific bruteforcer as an optimization so I want it ideally to be as fast as possible.
Currently Iam doing:
// count the number of unique elements
int uniqueCount(v16n a) {
alignas(16) unsigned char v[16];
_mm_store_si128((v16n*)v, a);
int count = 1;
for(int i = 1; i < 16; i++) {
int j;
for(j = 0; j < i; j++)
if(v[i] == v[j])
break;
if(i == j) count++;
}
return count;
}