Visual Studio 2010

Visual Studio 2010 SP1 is required.

Microsoft Specific

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

__m256i _mm256_cmov_si256 (
   __m256i src1,
   __m256i src2,
   __m256i selector

[in] src1

A 256-bit parameter.

[in] src2

A 256-bit parameter.

[in] selector

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

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





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()
    __m256i a, b, selector, d;
    int i;
    a.m256i_u64[3] = 0xffffffffffffffffll;
    a.m256i_u64[2] = 0xeeeeeeeeeeeeeeeell;
    a.m256i_u64[1] = 0xccccccccccccccccll;
    a.m256i_u64[0] = 0x8888888888888888ll;
    b.m256i_u64[3] = 0x0000000000000000ll;
    b.m256i_u64[2] = 0x1111111111111111ll;
    b.m256i_u64[1] = 0x3333333333333333ll;
    b.m256i_u64[0] = 0x7777777777777777ll;
    selector.m256i_u64[3] = 0xfedcba9876543210ll;
    selector.m256i_u64[2] = 0x0123456789abcdefll;
    selector.m256i_u64[1] = 0xfedcba9876543210ll;
    selector.m256i_u64[0] = 0x0123456789abcdefll;
    d = _mm256_cmov_si256(a, b, selector);
    printf_s("a:        %016I64x %016I64x\n",
              a.m256i_u64[3], a.m256i_u64[2]);
    printf_s("          %016I64x %016I64x\n",
              a.m256i_u64[1], a.m256i_u64[0]);
    printf_s("b:        %016I64x %016I64x\n",
              b.m256i_u64[3], b.m256i_u64[2]);
    printf_s("          %016I64x %016I64x\n",
              b.m256i_u64[1], b.m256i_u64[0]);
    printf_s("selector  %016I64x %016I64x\n",
              selector.m256i_u64[3], selector.m256i_u64[2]);
    printf_s("          %016I64x %016I64x\n",
              selector.m256i_u64[1], selector.m256i_u64[0]);
    printf_s("result:   %016I64x %016I64x\n",
              d.m256i_u64[3], d.m256i_u64[2]);
    printf_s("          %016I64x %016I64x\n",
              d.m256i_u64[1], d.m256i_u64[0]);
a:        ffffffffffffffff eeeeeeeeeeeeeeee
          cccccccccccccccc 8888888888888888
b:        0000000000000000 1111111111111111
          3333333333333333 7777777777777777
selector  fedcba9876543210 0123456789abcdef
          fedcba9876543210 0123456789abcdef
result:   fedcba9876543210 1032547698badcfe
          cdef89ab45670123 76543210fedcba98

Community Additions