_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 );
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.
#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