popcntd
Population Count Doubleword
popcntd RA, RS
Counts the number of set bits (1s) in a 64-bit register.
Encoding
Binary Layout
31
0:5
RS
6:10
RA
11:15
00000
16:20
506
21:30
/
31
Operands
-
RA
Target Register -
RS
Source Register
Example
popcntd r3, r4
// Hamming weight of r4.
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 (population count) in a 64-bit general-purpose register and stores the count in another register. This is a base category instruction that produces the count of 1-bits across the entire doubleword with no condition register or status updates.
Operation
RA ← popcount(RS[0:63])
Programming Note
The popcntd instruction is useful for counting the number of set bits (1s) in a 64-bit value. It operates on each doubleword independently, so if you're working with 128-bit values, ensure that both halves are processed separately. This instruction does not require any special alignment and can be executed at user privilege level. Be cautious when using this instruction in performance-critical sections, as it may have varying execution times depending on the input data.