i need the function that get the 32bits data input and the output is the array of number of the set bits.

ex:
input is 1b -> output is 1b
11b -> 01b, 10b
1011b -> 1000b, 10b, 1b

the simplest way is just loop and test each bit.
is there any other way faster?

is there any instruction that give the "least significant set bit"
such as,
100101b -> 1 ; the first bit is the least significant bit.
100100b -> 3 ; the third bit is the least significant bit.

if we have that instruction, so we can make the above function faster than loop 32 times.

or does it beter to use the database of all possible input or may be only 8 or 16 bits input?

ps: sorry for my poor english.
Posted on 2001-10-19 17:58:39 by doby
i've found that instruction, BSF and BSR for bit scan forward and reverse.
Posted on 2001-10-20 05:10:25 by doby