_mm_packus_epi32
Microsoft Specific
Emits the Streaming SIMD Extensions 4 (SSE4) instruction packusdw. This instruction converts four signed 32-bit integers into 8 unsigned 16-bit integers by using unsigned saturation.
__m128i _mm_packus_epi32(
__m128i a,
__m128i b
);
Parameters
[in] a
A 128-bit parameter that contains four 32-bit integers.[in] b
A 128-bit parameter that contains four 32-bit integers.
Result value
A 128-bit value that contains eight unsigned 16-bit integers. The result values are defined by the following equations:
r0 := (a0 < 0) ? 0 : ((a0 > 0xffff) ? 0xffff : a0)
r1 := (a1 < 0) ? 0 : ((a1 > 0xffff) ? 0xffff : a1)
r2 := (a2 < 0) ? 0 : ((a2 > 0xffff) ? 0xffff : a2)
r3 := (a3 < 0) ? 0 : ((a3 > 0xffff) ? 0xffff : a3)
r4 := (b0 < 0) ? 0 : ((b0 > 0xffff) ? 0xffff : b0)
r5 := (b1 < 0) ? 0 : ((b1 > 0xffff) ? 0xffff : b1)
r6 := (b2 < 0) ? 0 : ((b2 > 0xffff) ? 0xffff : b2)
r7 := (b3 < 0) ? 0 : ((b3 > 0xffff) ? 0xffff : b3)
Requirements
Intrinsic |
Architecture |
---|---|
_mm_packus_epi32 |
x86, x64 |
Header file <smmintrin.h>
Remarks
r0-r7 are the sequentially ordered 16-bit components of return value r. r0 is the least significant 16 bits. a0-a3 and b0-b3 are the sequentially ordered 32-bit components of parameters a and b. a0 and b0 indicates the least significant 32 bits.
Before you use this intrinsic, software must ensure that the processor supports the instruction.
Example
#include <stdio.h>
#include <smmintrin.h>
int main ()
{
__m128i a, b;
a.m128i_i32[0] = 0;
a.m128i_i32[1] = -1;
a.m128i_i32[2] = 70000;
a.m128i_i32[3] = 128;
b.m128i_i32[0] = -512;
b.m128i_i32[1] = 5200;
b.m128i_i32[2] = 32768;
b.m128i_i32[3] = 65536;
__m128i res = _mm_packus_epi32(a, b);
printf_s("Original a: %8d%8d%8d%8d\nOriginal b: %8d%8d%8d%8d\n",
a.m128i_i32[0], a.m128i_i32[1], a.m128i_i32[2], a.m128i_i32[3],
b.m128i_i32[0], b.m128i_i32[1], b.m128i_i32[2], b.m128i_i32[3]);
printf_s("Result res: %8d%8d%8d%8d\n\t%12d%8d%8d%8d\n",
res.m128i_u16[0], res.m128i_u16[1], res.m128i_u16[2],
res.m128i_u16[3], res.m128i_u16[4], res.m128i_u16[5],
res.m128i_u16[6], res.m128i_u16[7]);
return 0;
}
Original a: 0 -1 70000 128 Original b: -512 5200 32768 65536 Result res: 0 0 65535 128 0 5200 32768 65535