popcntw

Population Count Word

popcntw RA, RS

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

popcntw r3, r4

// Hamming weight of 32-bit word.

Encoding

Binary Layout
31
0
RS
6
RA
11
00000
16
378
21
/
31
 
Format X-form
Opcode 0x7C0002F4
Extension Base

Operands

  • RA
    Target Register
  • RS
    Source Register