vsrh

Vector Shift Right Halfword

vsrh vD, vA, vB

Shifts the contents of each element in a vector right by a specified number of bits.

Details

The Vector Shift Right Halfword instruction 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 on the least significant side are lost, and zeros are filled in on the most significant side.

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(EXTZ(src1) >> src2)
end

Programming Note

The vsrh instruction is used to perform element-wise right shifts on halfwords within a vector. Ensure that the shift amounts in the second source vector are within the range of 0-15 to avoid unexpected behavior. This instruction requires the VEC bit in the MSR register to be set; otherwise, it will raise an exception. Be cautious with alignment as unaligned access might lead to performance penalties or exceptions depending on the system configuration.

Example

vsrh vd, va, vb

Encoding

Binary Layout
000100
0
vD
6
vA
11
vB
16
01001
21
000100
26
 
Format VX-form
Opcode 0x10000244
Extension VMX (AltiVec)
Registers Altered MSR

Operands

  • vD
    Target
  • vA
    Data
  • vB
    Shift
  • VRT
    Target Vector Register
  • VRA
    Source Vector Register
  • VRB
    Source Vector Register