popcntw
Population Count Word
popcntw RA, RS
Counts the number of set bits (1s) in the lower 32 bits of a register.
Encoding
Binary Layout
31
0:5
RS
6:10
RA
11:15
00000
16:20
378
21:30
/
31
Operands
-
RA
Target Register -
RS
Source Register
Example
popcntw r3, r4
// Hamming weight of 32-bit word.
Related
Across architectures
Population Count : how x86, ARM, RISC-V, and PowerISA each do this.
More in Base
Reference
View in PowerISA v3.1C Specification ↗
OPF Power ISA v3.1C
Description
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.
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.