_mm_hsub_epi16
Microsoft Specific
Emits the Supplemental Streaming SIMD Extensions 3 (SSSE3) instruction phsubw. This instruction computes the difference between the elements of two 128-bit parameters.
__m128i _mm_hsub_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 input parameter elements.
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_hsub_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 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] = 100;
a.m128i_i16[3] = -100;
a.m128i_i16[4] = -1000;
a.m128i_i16[5] = 1000;
a.m128i_i16[6] = 100;
a.m128i_i16[7] = 52;
b.m128i_i16[0] = -128;
b.m128i_i16[1] = -64;
b.m128i_i16[2] = 32;
b.m128i_i16[3] = 4096;
b.m128i_i16[4] = 2;
b.m128i_i16[5] = -2;
b.m128i_i16[6] = 32000;
b.m128i_i16[7] = 0;
__m128i res = _mm_hsub_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: 1 1 100 -100
-1000 1000 100 52
Original b: -128 -64 32 4096
2 -2 32000 0
Result res: 0 200 -2000 48
-64 -4064 4 32000