vavguw

Vector Average Unsigned Word

vavguw vD, vA, vB

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

Details

The Vector Average Unsigned Word instruction computes the average of corresponding unsigned word elements from two source vectors and stores the result in a destination vector. Each word element is treated as an unsigned integer, summed, incremented by one, right-shifted by one bit, and then truncated to fit into a word.

Pseudocode Operation

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

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

Programming Note

The vavguw instruction is used to compute the average of unsigned word elements from two vectors. 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 processes each 32-bit word element independently, so alignment requirements are not strict. Be cautious with potential overflow when summing large unsigned integers.

Example

vavguw vd, va, vb

Encoding

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

Operands

  • vD
    Target
  • vA
    Src A
  • vB
    Src B