vctzh

Vector Count Trailing Zeros Halfword

vctzh vD, vB

Counts trailing zeros in each halfword.

Details

The vctzh instruction counts the number of trailing zero bits in each halfword element of a vector register and stores the result in another vector register. It processes each of the 8 halfwords in the source vector, counting zeros from the least significant bit until it encounters a '1'. The count is then stored in the corresponding position in the destination vector.

Pseudocode Operation

if MSR.VEC=0 then Vector_Unavailable()
do i = 0 to 7
   n ←0
   do while n < 16
      if VSR[VRB+32].hword[i].bit[15-n] = 0b1 then
         leave
      n ←n + 1
   end
   VSR[VRT+32].hword[i] ←CHOP16(EXTZ(n))
end

Programming Note

The vctzh instruction is useful for counting trailing zeros in each halfword of a vector, which can be helpful in bit manipulation and data compression tasks. Ensure that the Vector Facility (VEC) is enabled in the MSR register to avoid a Vector_Unavailable exception. The instruction processes 8 halfwords per vector register, so ensure your data is properly aligned and structured for optimal performance.

Example

vctzh vd, vb

Encoding

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

Operands

  • vD
    Target
  • vB
    Source