We recommend using Visual Studio 2017
This documentation is archived and is not being maintained.

_mm_cmov_si128

Visual Studio 2010

Visual Studio 2010 SP1 is required.

Microsoft Specific

Generates the XOP instruction vpcmov to do a bitwise conditional move of its first two sources depending on the value of its third source.

__m128i _mm_cmov_si128 (
   __m128i src1,
   __m128i src2,
   __m128i selector
);

[in] src1

A 128-bit parameter.

[in] src2

A 128-bit parameter.

[in] selector

A 128-bit parameter that selects bits from src1 and src2.

A 128-bit result r that contains bits from src1 and src2. The bit chosen depends on selector.

Intrinsic

Architecture

_mm_cmov_si128

XOP

Header file <intrin.h>

Each bit in the result is selected (copied) from the corresponding bit position in either src1 or src2, depending on the value of that bit position in selector. If the bit in selector is a 1, then the bit from src1 is selected; otherwise, the bit from src2 is selected.

The vpcmov instruction is part of the XOP family of instructions. Before you use this intrinsic, you must ensure that the processor supports this instruction. To determine hardware support for this instruction, call the __cpuid intrinsic with InfoType = 0x80000001 and check bit 11 of CPUInfo[2] (ECX). This bit is 1 when the instruction is supported, and 0 otherwise.

#include <stdio.h>
#include <intrin.h>
int main()
{
    __m128i a, b, selector, d;
    int i;
    a.m128i_u64[1] = 0xccccccccccccccccll;
    a.m128i_u64[0] = 0x8888888888888888ll;
    b.m128i_u64[1] = 0x3333333333333333ll;
    b.m128i_u64[0] = 0x7777777777777777ll;
    selector.m128i_u64[1] = 0xfedcba9876543210ll;
    selector.m128i_u64[0] = 0x0123456789abcdefll;
    d = _mm_cmov_si128(a, b, selector);
    printf_s("a:        %016I64x %016I64x\n",
              a.m128i_u64[1], a.m128i_u64[0]);
    printf_s("b:        %016I64x %016I64x\n",
              b.m128i_u64[1], b.m128i_u64[0]);
    printf_s("selector  %016I64x %016I64x\n",
              selector.m128i_u64[1], selector.m128i_u64[0]);
    printf_s("result:   %016I64x %016I64x\n",
              d.m128i_u64[1], d.m128i_u64[0]);
}
a:        cccccccccccccccc 8888888888888888
b:        3333333333333333 7777777777777777
selector  fedcba9876543210 0123456789abcdef
result:   cdef89ab45670123 76543210fedcba98
Show: