vsel

Vector Select

vsel vD, vA, vB, vC

Bitwise selection. copies bits from vA if the corresponding bit in vC is 0, or from vB if vC is 1. (Like 'mux').

Details

The vsel instruction selects elements from two vector registers (VRA and VRB) based on the corresponding bits in a mask vector register (VRC). The result is stored in another vector register (VRT).

Pseudocode Operation

if MSR.VEC=0 then
    Vector_Unavailable()
src1 ←VSR[VRA+32]
src2 ←VSR[VRB+32]
mask ←VSR[VRC+32]
VSR[VRT+32] ←(src1 & ¬mask) | (src2 & mask)

Programming Note

The vsel instruction requires the Vector Facility to be enabled in the MSR. Ensure that VRA, VRB, and VRC are properly aligned and contain valid data. The result is stored in VRT, so ensure it is not being used elsewhere in your computation until the operation completes.

Example

vsel v1, v2, v3, v4

Encoding

Binary Layout
0
0
VRT
6
VRA
11
VRB
16
VRC
21
42
 
Format VA-form
Opcode 0x1000002A
Extension VMX (AltiVec)
Registers Altered MSR

Operands

  • vD
    Target
  • vA
    Source 0
  • vB
    Source 1
  • vC
    Control (Selector)
  • VRT
    Target Vector Register
  • VRA
    Source Vector Register
  • VRB
    Source Vector Register
  • VRC
    Mask Vector Register