共用方式為


_mm_blendv_epi8

Microsoft Specific

Emits the Streaming SIMD Extensions 4 (SSE4) instruction pblendvb. This instruction blends packed 8-bit integers.

__m128i _mm_blendv_epi8( 
   __m128i a,
   __m128i b,
   __m128i mask 
);

Parameters

  • [in] a
    A 128-bit parameter that contains sixteen 8-bit integers to be blended.

  • [in] b
    A 128-bit parameter that contains sixteen 8-bit integers to be blended.

  • [in] mask
    A 128-bit mask that selects components for the blend operation.

Result value

A 128-bit result that consists of packed 8-bit integer values. Each value corresponds to one of the integers from parameter a or b, depending on bit settings that are specified by the mask parameter. The high bit of each corresponding mask byte determines the selection.

Requirements

Intrinsic

Architecture

_mm_blendv_epi8

x86, x64

Header file <smmintrin.h>

Remarks

The result is defined as follows:

r0 := (mask0 & 0x80) ? b0 : a0
r1 := (mask1 & 0x80) ? b1 : a1
...
r15 := (mask15 & 0x80) ? b15 : a15

Parameters a, b, and mask, and the return value r each consist of 128 bits. r0-r15, a0-a15, b0-b15, and mask0-mask15 are the sequentially ordered 8-bit components of these parameters, where r0, a0, b0, and mask0 indicate the least significant 8 bits.

Before using this intrinsic, software must ensure that the processor supports the instruction.

Example

#include <stdio.h>
#include <smmintrin.h>

int main () {
    __m128i a, b, mask;

    mask.m128i_u8[15] = 0x80;
    mask.m128i_u8[14] = 0x80;
    mask.m128i_u8[13] = 0x80;
    mask.m128i_u8[12] = 0x80;
    mask.m128i_u8[11] = 0x80;
    mask.m128i_u8[10] = 0x80;
    mask.m128i_u8[9] = 0x80;
    mask.m128i_u8[8] = 0x80;
    mask.m128i_u8[7] = 0x00;
    mask.m128i_u8[6] = 0x00;
    mask.m128i_u8[5] = 0x00;
    mask.m128i_u8[4] = 0x00;
    mask.m128i_u8[3] = 0x00;
    mask.m128i_u8[2] = 0x00;
    mask.m128i_u8[1] = 0x00;
    mask.m128i_u8[0] = 0x00;

    a.m128i_u64[1] = 0xFFFFFFFFFFFFFFFF;
    a.m128i_u64[0] = 0xEEEEEEEEEEEEEEEE;
    b.m128i_u64[1] = 0x8888888888888888;
    b.m128i_u64[0] = 0x7777777777777777;

    __m128i res = _mm_blendv_epi8( a, b, mask );

    printf_s("Original a: 0x%016I64x%016I64x\nOriginal b: 0x%016I64x%016I64x\n",
        a.m128i_u64[1], a.m128i_u64[0],
        b.m128i_u64[1], b.m128i_u64[0]);
    printf_s("Result res: 0x%016I64x%016I64x\n",
        res.m128i_u64[1], res.m128i_u64[0]);

    return 0;
}

Original a: 0xffffffffffffffffeeeeeeeeeeeeeeee
Original b: 0x88888888888888887777777777777777
Result res: 0x8888888888888888eeeeeeeeeeeeeeee

See Also

Concepts

Compiler Intrinsics