I'm designing a circuit that needs to check if the popcount (number of bit sets to 1) of two 16-bit vectors are equal. So what I need is to perform the operation
logic[15:0] A,B;
if (popcount(A) == popcount(B)) begin
...
end
(here popcount is assumed to be an already defined function)
The trivial solution is indeed to compute the actual values and compare them, but I was wondering if there is another way requiring less levels of logic to complete the operation. I tried to think about a way to exploit their parity, but without much success...