popcntw
Population Count Word
Counts the number of set bits (1s) in the lower 32 bits of a register.
Details
Counts the number of set bits in the lower 32 bits of a general-purpose register and stores the count in another register. This is a base category instruction that produces the count of 1-bits in the word, with the upper 32 bits of the result cleared and no condition register or status updates.
Pseudocode Operation
RA ← popcount(RS[32:63])
Programming Note
The popcntw instruction is useful for counting the number of set bits (1s) in a 32-bit word. It operates on each 32-bit segment of the source register, making it ideal for bit manipulation tasks where population count is needed. Ensure that the source and destination registers are properly aligned to avoid unexpected behavior. This instruction does not require any special privileges and will execute without exceptions if the operands are valid.
Example
// Hamming weight of 32-bit word.
Encoding
Operands
-
RA
Target Register -
RS
Source Register