Se recomienda usar Visual Studio 2017
Esta documentación está archivada y no tiene mantenimiento.


Microsoft Specific

Emits the Supplemental Streaming SIMD Extensions 3 (SSSE3) instruction phaddd. This instruction adds the elements of two 128-bit parameters.

__m128i _mm_hadd_epi32( 
   __m128i a,
   __m128i b

[in] a

A 128-bit parameter that contains four 32-bit signed integers.

[in] b

A 128-bit parameter that contains four 32-bit signed integers.

A 128-bit value that contains four 32-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 := b0 + b1
r3 := b2 + b3




x86, x64

Header file <tmmintrin.h>

r0-r3, a0-a3, and b0-b3 are the sequentially ordered 32-bit components of return value r and parameters a and b. r0, a0, and b0 are the least significant 32 bits.

Before you use this intrinsic, software must ensure that the underlying processor supports the instruction.

#include <stdio.h>
#include <tmmintrin.h>

int main ()
    __m128i a, b;

    a.m128i_i32[0] = -1;
    a.m128i_i32[1] = 1;
    a.m128i_i32[2] = 0;
    a.m128i_i32[3] = 65535;
    b.m128i_i32[0] = -65535;
    b.m128i_i32[1] = 0;
    b.m128i_i32[2] = 128;
    b.m128i_i32[3] = -32;

    __m128i res = _mm_hadd_epi32(a, b);

    printf_s("Original a: %8d\t%8d\t%8d\t%8d\nOriginal b: %8d\t%8d\t%8d\t%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\t%8d\t%8d\t%8d\n",
                res.m128i_i32[0], res.m128i_i32[1], res.m128i_i32[2], res.m128i_i32[3]);

    return 0;
Original a:       -1           1               0           65535
Original b:   -65535           0             128             -32
Result res:        0       65535          -65535              96