vpopcnth

Vector Population Count Halfword

vpopcnth vD, vB

Counts set bits in each halfword.

Encoding

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

Operands

  • vD
    Target
  • vB
    Source

Example

vpopcnth vd, vb

Registers Altered

MSR

Related

More in VMX (AltiVec)

Reference

Description

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

Operation

for i in 0 to 7 do
  count ← 0
  halfword ← vB[i*16 : i*16+15]
  for j in 0 to 15 do
    if halfword[j] = 1 then
      count ← count + 1
  vD[i*16 : i*16+15] ← count

Programming Note

This instruction is useful for counting the number of set bits in each halfword of a vector, which can be helpful in various bit manipulation tasks. Ensure that the Vector Facility (VEC) is enabled in the Machine State Register (MSR) before using this instruction; otherwise, it will raise an exception. The operation is performed on 8 halfwords per vector register, and there are no specific alignment requirements for the data being processed.