Export (0) Print
Expand All
Expand Minimize

_mm_hadds_pi16

Microsoft Specific

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

__m64 _mm_hadds_pi16( 
   __m64 a,
   __m64 b
);

[in] a

A 64-bit parameter that contains four 16-bit signed integers.

[in] b

A 64-bit parameter that contains four 16-bit signed integers.

A 64-bit value that contains four 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 := SATURATE_16(a0 + a1)
r1 := SATURATE_16(a2 + a3)
r2 := SATURATE_16(b0 + b1)
r3 := SATURATE_16(b2 + b3)

Intrinsic

Architecture

_mm_hadds_pi16

x86, x64

Header file <tmmintrin.h>

r0-r3, a0-a3, and b0-b3 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.

SATURATE_16(x) is ((x > 32767) ? 32767 : ((x < -32768) ? -32768 : x))

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

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

int main ()
{
    __m64 a, b;

    a.m64_i16[0] = -1;
    a.m64_i16[1] = 1;
    a.m64_i16[2] = 4096;
    a.m64_i16[3] = 127;
    b.m64_i16[0] = -127;
    b.m64_i16[1] = 50;
    b.m64_i16[2] = 64;
    b.m64_i16[3] = -128;

    __m64 res = _mm_hadd_pi16(a, b);

    printf_s("Original a:\t%4d\t%4d\t%4d\t%4d\nOriginal b:\t%4d\t%4d\t%4d\t%4d\n",
                a.m64_i16[0], a.m64_i16[1], a.m64_i16[2], a.m64_i16[3],
                b.m64_i16[0], b.m64_i16[1], b.m64_i16[2], b.m64_i16[3]);
    printf_s("Result res:\t%4d\t%4d\t%4d\t%4d\n",
                res.m64_i16[0], res.m64_i16[1], res.m64_i16[2], res.m64_i16[3]);

    _mm_empty();

    return 0;
}
Original a: -1 1 4096 127 Original b: -127 50 64 -128 Result res: 0 4223 -77 -64

Community Additions

ADD
Show:
© 2014 Microsoft