Blend Packed Single-Precision Floating-Point Values

Encoding

EncodingOperand 1Operand 2Operand 3Operand 4
rmiModRM.reg[rw]ModRM.r/m[r]imm8
rvmiModRM.reg[w]VEX.vvvv[r]ModRM.r/m[r]imm8

Description

The (V)BLENDPS instruction conditionally moves single-precision floating-point values from the two source operands. From the control byte, each bit, if cleared, will move from the first source operand, and, if set, will move from the second source operand. The result is stored in the destination operand.

This instruction, despite being named as if it operates on floating-point numbers, will work on 32-bit integers as well.

All forms except the legacy SSE one will zero the upper (untouched) bits.

Operation

public void BLENDPS(SimdF32 dest, SimdF32 src, U8 mask)
{
    // if `mask.Bit[n]` is 0, `dest` will be copied into itself (i.e. nothing happens)
    if (mask.Bit[0])
        dest[0] = src[0];
    if (mask.Bit[1])
        dest[1] = src[1];
    if (mask.Bit[2])
        dest[2] = src[2];
    if (mask.Bit[3])
        dest[3] = src[3];
    // dest[4..] is unmodified
}

void VBLENDPS_Vex(SimdF32 dest, SimdF32 src1, SimdF32 src2, U8 mask, int kl)
{
    for (int n = 0; n < kl; n++)
        dest[n] = mask.Bit[n] ? src2[n] : src1[n];
    dest[kl..] = 0;
}
public void VBLENDPS_Vex128(SimdF32 dest, SimdF32 src1, SimdF32 src2, U8 mask) =>
    VBLENDPS_Vex(dest, src1, src2, mask, 4);
public void VBLENDPS_Vex256(SimdF32 dest, SimdF32 src1, SimdF32 src2, U8 mask) =>
    VBLENDPS_Vex(dest, src1, src2, mask, 8);

Intrinsics

Exceptions

SIMD Floating-Point

None.

Other Exceptions

VEX Encoded Form: See Type 4 Exception Conditions.