_mm_blend_epi16
Microsoft Specific
Emits the Streaming SIMD Extensions 4 (SSE4) instruction pblendw. This instruction blends packed 16-bit integers.
__m128i _mm_blend_epi16(
__m128i a,
__m128i b,
const int mask
);
Parameters
[in] a
A 128-bit parameter that contains eight 16-bit integers to be blended.[in] b
A 128-bit parameter that contains eight 16-bit integers to be blended.[in] mask
A constant mask that selects components for the blend operation.
Return value
A 128-bit result that consists of eight 16-bit integer values. Each value corresponds to one of the integers from parameter a or b depending on bit settings given by the mask parameter. If the corresponding flag bit is off, the value is selected from parameter a. Otherwise the value is from parameter b.
Requirements
Intrinsic |
Architecture |
---|---|
_mm_blend_epi16 |
x86, x64 |
Header file <smmintrin.h>
Remarks
The result is defined as follows:
r0 := (mask0 == 0) ? a0 : b0
r1 := (mask1 == 0) ? a1 : b1
...
r7 := (mask7 == 0) ? a7 : b7
The return value r and parameters a and b each consist of 128 bits. r0-r7, a0-a7, and b0-b7 are the sequentially ordered 16-bit components of these parameters, where r0, a0, and b0 indicate the least significant 16 bits.
maskiis bit i of parameter mask, where bit 0 indicates the least significant bit.
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;
const int mask = 0xF0;
a.m128i_u16[7] = 0xFFFF;
a.m128i_u16[6] = 0xEEEE;
a.m128i_u16[5] = 0xDDDD;
a.m128i_u16[4] = 0xCCCC;
a.m128i_u16[3] = 0xBBBB;
a.m128i_u16[2] = 0xAAAA;
a.m128i_u16[1] = 0x9999;
a.m128i_u16[0] = 0x8888;
b.m128i_u16[7] = 0xFEDC;
b.m128i_u16[6] = 0xBA98;
b.m128i_u16[5] = 0x7654;
b.m128i_u16[4] = 0x3210;
b.m128i_u16[3] = 0x0123;
b.m128i_u16[2] = 0x4567;
b.m128i_u16[1] = 0x89AB;
b.m128i_u16[0] = 0xCDEF;
__m128i res = _mm_blend_epi16( 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: 0xffffeeeeddddccccbbbbaaaa99998888
Original b: 0xfedcba98765432100123456789abcdef
Result res: 0xfedcba9876543210bbbbaaaa99998888