vpopcntd

Vector Population Count Doubleword

vpopcntd vD, vB

Counts set bits in each doubleword.

Encoding

Binary Layout
4
0:5
vD
6:10
0
11:15
vB
16:20
1987
21:31
 
Format VX-form
Opcode 0x100007C3
Extension VMX (AltiVec)

Operands

  • vD
    Target
  • vB
    Source

Example

vpopcntd vd, vb

Registers Altered

MSR

Related

More in VMX (AltiVec)

Reference

Description

Counts the number of set bits (population count) in each of the 2 doubleword elements in vB and stores the result in the corresponding doubleword of vD. Each result is an unsigned integer in the range 0-64. No status flags are affected. This instruction is part of the VMX (AltiVec) extension.

Operation

for i in 0 to 1 do
  count ← 0
  doubleword ← vB[i*64 : i*64+63]
  for j in 0 to 63 do
    if doubleword[j] = 1 then
      count ← count + 1
  vD[i*64 : i*64+63] ← count

Programming Note

The vpopcntd instruction is useful for counting the number of set bits in each 64-bit element of a vector. Ensure that the Vector Facility (MSR.VEC) is enabled before using this instruction; otherwise, it will raise an exception. This instruction operates on two doublewords per vector register, and results are stored in the corresponding positions of the destination vector.