vctzb

Vector Count Trailing Zeros Byte

vctzb vD, vB

Counts the number of trailing zero bits in each byte element of a vector register.

Details

For vctzb, the number of consecutive zero bits starting at bit 7 of each byte element in VSR[VRB+32] is placed into the corresponding byte element in VSR[VRT+32]. The count ranges from 0 to 8, inclusive.

Pseudocode Operation

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

Programming Note

The vctzb instruction counts the number of trailing zero bits in each byte of the source vector, storing the result in the destination vector. Ensure that the Vector Facility is enabled by checking and setting the VEC bit in the MSR register. This instruction operates on 16-byte vectors and processes each byte independently. Be cautious with alignment; while not strictly required, proper alignment can improve performance.

Example

vctzb vd, vb

Encoding

Binary Layout
4
0
VRT
6
28
11
VRB
16
1538
21
 
Format VX-form
Opcode 0x10000702
Extension VMX (AltiVec)
Registers Altered MSR

Operands

  • vD
    Target
  • vB
    Source
  • VRT
    Target Vector Register
  • VRB
    Source Vector Register