popcntd
Population Count Doubleword
Counts the number of set bits (1s) in a 64-bit register.
Details
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.
Pseudocode 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.
Example
// Hamming weight of r4.
Encoding
Operands
-
RA
Target Register -
RS
Source Register