vavguh

Vector Average Unsigned Halfword

vavguh vD, vA, vB

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

Details

The Vector Average Unsigned Halfword instruction (vavguh) computes the average of corresponding halfwords from two source vectors, rounding up by adding 1 before shifting right by 1 bit. The result is stored in a destination vector.

Pseudocode Operation

if MSR.VEC=0 then Vector_Unavailable()
do i = 0 to 7
   src1 ←EXTZ(VSR[VRA+32].hword[i])
   src2 ←EXTZ(VSR[VRB+32].hword[i])

   VSR[VRT+32].hword[i] ←CHOP16((src1 + src2 + 1) >> 1)
end

Programming Note

The vavguh instruction is used to compute the average of corresponding halfwords from two source vectors, rounding up. Ensure that the Vector Facility (VEC) bit in the Machine State Register (MSR) is set; otherwise, a Vector_Unavailable exception will be raised. This instruction operates on 16-bit unsigned integers and stores the result in the destination vector. Be cautious of overflow when adding the two source halfwords before rounding.

Example

vavguh vd, va, vb

Encoding

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

Operands

  • vD
    Target
  • vA
    Src A
  • vB
    Src B