vavgub

Vector Average Unsigned Byte

vavgub vD, vA, vB

Computes (a+b+1)/2 for bytes.

Details

The vavgub instruction performs an average operation on corresponding bytes of two source vectors, VRA and VRB, treating the values as unsigned integers. It adds each pair of corresponding bytes from VRA and VRB, increments the sum by 1, shifts it right by 1 bit to perform rounding, and stores the result in the destination vector VRT.

Pseudocode Operation

if MSR.VEC=0 then Vector_Unavailable()
do i = 0 to 15
   src1 ←EXTZ(VSR[VRA+32].byte[i])
   src2 ←EXTZ(VSR[VRB+32].byte[i])
   VSR[VRT+32].byte[i] ←CHOP8((src1 + src2 + 1) >> 1)
end

Programming Note

The vavgub instruction is commonly used for averaging pixel values in image processing tasks. Ensure that the source vectors are properly aligned to avoid performance penalties. This instruction operates at user privilege level and will raise an exception if the vector facility is not enabled (MSR.VEC=0).

Example

vavgub vd, va, vb

Encoding

Binary Layout
4
0
vD
6
vA
11
vB
16
1026
21
 
Format VA-form
Opcode 0x10000402
Extension VMX (AltiVec)
Registers Altered MSR

Operands

  • vD
    Target
  • vA
    Src A
  • vB
    Src B