_mm_mulhrs_epi16

Microsoft Specific

Emits the Supplemental Streaming SIMD Extensions 3 (SSSE3) instruction pmulhrsw. This instruction multiplies two sets of 16-bit integers.

__m128i _mm_mulhrs_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. The result can be expressed by the following equations.

r0 := INT16(((a0 * b0) + 0x4000) >> 15)
r1 := INT16(((a1 * b1) + 0x4000) >> 15)
...
r7 := INT16(((a7 * b7) + 0x4000) >> 15)

Requirements

Intrinsic

Architecture

_mm_mulhrs_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 indicates 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, final;

    a.m128i_i16[0] = -0x5CEE;
    a.m128i_i16[1] = 0x0105;
    a.m128i_i16[2] = 0x3DA9;
    a.m128i_i16[3] = -0x7FFF;
    a.m128i_i16[4] = 0x7FFF;
    a.m128i_i16[5] = 0x1111;
    a.m128i_i16[6] = -0x219D;
    a.m128i_i16[7] = -0x1DBC;

    b.m128i_i16[0] = 0x4000;
    b.m128i_i16[1] = -0x510A;
    b.m128i_i16[2] = 0x209D;
    b.m128i_i16[3] = -0x7FFF;
    b.m128i_i16[4] = 0x0000;
    b.m128i_i16[5] = 0x2222;
    b.m128i_i16[6] = 0x1027;
    b.m128i_i16[7] = 0x7AEF;

    for (int index = 0; index < 8; index++)
    {
        final.m128i_i16[index] = ((a.m128i_i16[index] * b.m128i_i16[index]) + 0x4000) >> 15;
    }

    __m128i res = _mm_mulhrs_epi16(a, b);

    printf_s("Res0 should be %d: %d\nRes1 should be %d: %d\n",
                final.m128i_i16[0], res.m128i_i16[0],
                final.m128i_i16[1], res.m128i_i16[1]);
    printf_s("Res2 should be %d: %d\nRes3 should be %d: %d\n",
                final.m128i_i16[2], res.m128i_i16[2],
                final.m128i_i16[3], res.m128i_i16[3]);
    printf_s("Res4 should be %d: %d\nRes5 should be %d: %d\n",
                final.m128i_i16[4], res.m128i_i16[4],
                final.m128i_i16[5], res.m128i_i16[5]);
    printf_s("Res6 should be %d: %d\nRes7 should be %d: %d\n",
                final.m128i_i16[6], res.m128i_i16[6],
                final.m128i_i16[7], res.m128i_i16[7]);

    return 0;
}

Res0 should be -11895: -11895
Res1 should be -165: -165
Res2 should be 4022: 4022
Res3 should be 32766: 32766
Res4 should be 0: 0
Res5 should be 1165: 1165
Res6 should be -1086: -1086
Res7 should be -7311: -7311

See Also

Concepts

Compiler Intrinsics