_mm_hsubs_epi16

Microsoft Specific

Emits the Supplemental Streaming SIMD Extensions 3 (SSSE3) instruction phsubsw. This instruction computes the difference between the elements of two 128-bit parameters.

__m128i _mm_hsubs_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 that contains eight 16-bit signed integers.

Return value

A 128-bit value that contains eight 16-bit signed integers. Each integer is the difference 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(a4 - a5)
r3 := SATURATE_16(a6 - a7)
r4 := SATURATE_16(b0 - b1)
r5 := SATURATE_16(b2 - b3)
r6 := SATURATE_16(b4 - b5)
r7 := SATURATE_16(b6 - b7)

Requirements

Intrinsic

Architecture

_mm_hsubs_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.

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

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

Example

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

int main ()
{
    __m128i a, b;

    a.m128i_i16[0] = 32;
    a.m128i_i16[1] = 32;
    a.m128i_i16[2] = 4096;
    a.m128i_i16[3] = -4096;
    a.m128i_i16[4] = -128;
    a.m128i_i16[5] = 128;
    a.m128i_i16[6] = 100;
    a.m128i_i16[7] = 32767;
    b.m128i_i16[0] = 32700;
    b.m128i_i16[1] = -1000;
    b.m128i_i16[2] = -8192;
    b.m128i_i16[3] = 30000;
    b.m128i_i16[4] = 512;
    b.m128i_i16[5] = 0;
    b.m128i_i16[6] = 0;
    b.m128i_i16[7] = 2;

    __m128i res = _mm_hsubs_epi16(a, b);

    printf_s("Original a:\t%6d\t%6d\t%6d\t%6d\n\t\t%6d\t%6d\t%6d\t%6d\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%6d\t%6d\t%6d\t%6d\n\t\t%6d\t%6d\t%6d\t%6d\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%6d\t%6d\t%6d\t%6d\n\t\t%6d\t%6d\t%6d\t%6d\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:         32      32    4096   -4096
                  -128     128     100   32767
Original b:      32700   -1000   -8192   30000
                   512       0       0       2
Result res:          0    8192    -256  -32667
                 32767  -32768     512      -2

See Also

Concepts

Compiler Intrinsics