vsrah

Vector Shift Right Algebraic Halfword

vsrah vD, vA, vB

Arithmetic right shift of halfwords.

Details

The Vector Shift Right Algebraic Halfword instruction (vsrah) shifts each halfword element of the source vector right by a specified number of bits. The shift amount is determined by the low-order 4 bits of the corresponding halfword in the second source vector. Bits shifted out are discarded, and copies of the sign bit (bit 0) are supplied to the vacated positions on the left.

Pseudocode Operation

if MSR.VEC=0 then Vector_Unavailable()
do i = 0 to 7
   src1 ←VSR[VRA+32].hword[i]
   src2 ←VSR[VRB+32].hword[i].bit[12:15]
   VSR[VRT+32].hword[i] ←CHOP16(EXTS(src1) >> src2)
end

Programming Note

The vsrah instruction is used to perform right algebraic shifts on halfword elements of a vector. Ensure that the Vector Facility (MSR.VEC) is enabled before using this instruction; otherwise, a Vector_Unavailable exception will be raised. The shift amount for each element is determined by the low-order 4 bits of the corresponding element in the second source vector. Be cautious with alignment as halfword operations require proper alignment to avoid undefined behavior.

Example

vsrah vd, va, vb

Encoding

Binary Layout
4
0
vD
6
vA
11
vB
16
836
21
 
Format VX-form
Opcode 0x10000344
Extension VMX (AltiVec)
Registers Altered MSR

Operands

  • vD
    Target
  • vA
    Data
  • vB
    Shift