vpopcnth

Vector Population Count Halfword

vpopcnth vD, vB

Counts set bits in each halfword.

Details

The Vector Population Count Halfword instruction counts the number of bits set to 1 in each halfword element of the source vector and places these counts into corresponding halfword elements of the result vector.

Pseudocode Operation

if MSR.VEC=0 then Vector_Unavailable()
do i = 0 to 7
    n ←0
    do j = 0 to 15
        n ←n + VSR[VRB+32].hword[i].bit[j]
    end
    VSR[VRT+32].hword[i] ←n
end

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.

Example

vpopcnth vd, vb

Encoding

Binary Layout
4
0
vD
6
0
11
vB
16
1859
21
 
Format VX-form
Opcode 0x10000743
Extension VMX (AltiVec)
Registers Altered MSR

Operands

  • vD
    Target
  • vB
    Source