BLENDPS: Blend Packed Single-Precision Floating-Point Values

For information about interpreting this page, see the help page.
Opcode and MnemonicEncoding16 bit Mode32 bit Mode64 bit ModeCPUID Feature FlagDescription
66 0F 3A 0C /r ib
BLENDPS xmm1, xmm2/m128, imm8
LEGACYInvalidValidValidSSE4_1Selects packed single-precision floating-point values from xmm1 and xmm2/m128 from a mask specified in imm8. Stores the result in xmm1.
VEX.128.66.0F3A.WIG 0C /r ib
VBLENDPS xmm1, xmm2, xmm3/m128, imm8
VEXInvalidValidValidAVXSelects packed single-precision floating-point values from xmm2 and xmm3/m128 from a mask specified in imm8. Stores the result in xmm1.
VEX.256.66.0F3A.WIG 0C /r ib
VBLENDPS ymm1, ymm2, ymm3/m256, imm8
VEXInvalidValidValidAVXSelects packed single-precision floating-point values from ymm2 and ymm3/m256 from a mask specified in imm8. Stores the result in ymm1.

Encoding

EncodingOperand 1Operand 2Operand 3Operand 4
LEGACYModRM.reg[rw]ModRM.r/m[r]imm8[3:0]
VEXModRM.reg[w]VEX.vvvv[r]ModRM.r/m[r]imm8

Description

The (V)BLENDPS instruction conditionally moves single-precision floating-point values from the second source operand into the first 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 versions except the legacy SSE version zero the unused upper SIMD register bits.

Operation

This pseudo-code uses C# syntax. A list of the types used is available here.
public void BLENDPS(SimdF32 dest, SimdF32 src, byte mask)
{
  // If `mask[n]` is 0, `dest` will be copied into itself (i.e. nothing will happen)
  if (mask[0])
    dest[0] = src[0];
  if (mask[1])
    dest[1] = src[1];
  if (mask[2])
    dest[2] = src[2];
  if (mask[3])
    dest[3] = src[3];
  // dest[4..Simd.MAX] (unmodified)
}

void VBLENDPS_Vex(SimdF32 dest, SimdF32 src1, SimdF32 src2, byte mask, int kl)
{
  for (int n = 0; n < kl, n++) {
    if (mask[n])
      dest[n] = src2[n];
    else
      dest[n] = src1[n];
  }
  dest[kl..Simd.MAX] = 0;
}
public void VBLENDPS_Vex128(SimdF32 dest, SimdF32 src1, SimdF32 src2, byte mask)
{
  VBLENDPS_Vex(dest, src1, src2, mask, 4);
}
public void VBLENDPS_Vex256(SimdF32 dest, SimdF32 src1, SimdF32 src2, byte mask)
{
  VBLENDPS_Vex(dest, src1, src2, mask, 8);
}

C Intrinsics

Exceptions

SIMD Floating-Point

None

Other

See Exceptions Type 4.