vclzb

Vector Count Leading Zeros Byte

vclzb vD, vB

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

Details

For vclzb, the number of consecutive zero bits starting at bit 0 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[n] = 0b1 then
            leave
        n ←n + 1
    end
    VSR[VRT+32].byte[i] ←n
end

Programming Note

The vclzb instruction counts leading zeros in each byte of the input vector. Ensure that the Vector Facility is enabled by checking and setting the appropriate bit in the MSR register. This instruction operates on 16-byte vectors, processing each byte individually. Be cautious with alignment; while not strictly required, proper alignment can optimize performance. The result is a vector where each element contains the count of leading zeros from the corresponding input byte.

Example

vclzb vd, vb

Encoding

Binary Layout
0
0
VRT
6
VRB
11
0
16
0
21
0
26
0
30
0
31
0
0
0
0
0
0
0
0
 
Format VX-form
Opcode 0x10000702
Extension VMX (AltiVec)
Registers Altered MSR

Operands

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