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.

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.

i've found that instruction, BSF and BSR for bit scan forward and reverse.