Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Microsoft Specific
Emits the Supplemental Streaming SIMD Extensions 3 (SSSE3) instruction phaddw. This instruction adds the elements of two 128-bit parameters.
__m128i _mm_hadd_epi16(
__m128i a,
__m128i b
);
Parameters
[in] a
A 128-bit parameter that contains eight 16-bit signed integers.[in] b
A 128-bit parameter contains eight 16-bit signed integers.
Return value
A 128-bit value that contains eight 16-bit signed integers. Each integer is the sum between adjacent pairs of elements in the input parameters.
The result can be expressed with the following equations:
r0 := a0 + a1
r1 := a2 + a3
r2 := a4 + a5
r3 := a6 + a7
r4 := b0 + b1
r5 := b2 + b3
r6 := b4 + b5
r7 := b6 + b7
Requirements
Intrinsic |
Architecture |
---|---|
_mm_hadd_epi16 |
x86, x64 |
Header file <tmmintrin.h>
Remarks
r0-r7, a0-a7, and b0-b7 are the sequentially ordered 16-bit components of return value r and parameters a and b. r0, a0, and b0 are the least significant 16 bits.
Before you use this intrinsic, software must ensure that the underlying processor supports the instruction.
Example
#include <stdio.h>
#include <tmmintrin.h>
int main ()
{
__m128i a, b;
a.m128i_i16[0] = -1;
a.m128i_i16[1] = 1;
a.m128i_i16[2] = 0;
a.m128i_i16[3] = 8;
a.m128i_i16[4] = -8;
a.m128i_i16[5] = 0;
a.m128i_i16[6] = 2;
a.m128i_i16[7] = 2;
b.m128i_i16[0] = -2;
b.m128i_i16[1] = -2;
b.m128i_i16[2] = 1000;
b.m128i_i16[3] = 2000;
b.m128i_i16[4] = 128;
b.m128i_i16[5] = 32;
b.m128i_i16[6] = 81;
b.m128i_i16[7] = -21;
__m128i res = _mm_hadd_epi16(a, b);
printf_s("Original a: \t%d\t%d\t%d\t%d\n\t\t%d\t%d\t%d\t%d\n",
a.m128i_i16[0], a.m128i_i16[1], a.m128i_i16[2], a.m128i_i16[3],
a.m128i_i16[4], a.m128i_i16[5], a.m128i_i16[6], a.m128i_i16[7]);
printf_s("Original b: \t%d\t%d\t%d\t%d\n\t\t%d\t%d\t%d\t%d\n",
b.m128i_i16[0], b.m128i_i16[1], b.m128i_i16[2], b.m128i_i16[3],
b.m128i_i16[4], b.m128i_i16[5], b.m128i_i16[6], b.m128i_i16[7]);
printf_s("Result res: \t%d\t%d\t%d\t%d\n\t\t%d\t%d\t%d\t%d\n",
res.m128i_i16[0], res.m128i_i16[1], res.m128i_i16[2], res.m128i_i16[3],
res.m128i_i16[4], res.m128i_i16[5], res.m128i_i16[6], res.m128i_i16[7]);
return 0;
}
Original a: -1 1 0 8 -8 0 2 2 Original b: -2 -2 1000 2000 128 32 81 -21 Result res: 0 8 -8 4 -4 3000 160 60