共用方式為


_mm_sign_epi16

Microsoft Specific

Emits the Supplemental Streaming SIMD Extensions 3 (SSSE3) instruction psignw. This instruction negates or clears 16-bit signed integers of a 128 bit parameter.

__m128i _mm_sign_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

The return value can be expressed with the following equations.

r0 := (b0 < 0) ? -a0 : ((b0 == 0) ? 0 : a0)

r1 := (b1 < 0) ? -a1 : ((b1 == 0) ? 0 : a1)

...

r7 := (b7 < 0) ? -a7 : ((b7 == 0) ? 0 : a7)

Requirements

Intrinsic

Architecture

_mm_sign_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 underlying processor supports the instruction.

Example

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

int main ()
{
    __m128i a, b;

    a.m128i_i16[0] = 42;
    a.m128i_i16[1] = -3141;
    a.m128i_i16[2] = 128;
    a.m128i_i16[3] = 32000;
    a.m128i_i16[4] = -81;
    a.m128i_i16[5] = -5421;
    a.m128i_i16[6] = -999;
    a.m128i_i16[7] = 25;

    b.m128i_i16[0] = 1;
    b.m128i_i16[1] = 0;
    b.m128i_i16[2] = -1;
    b.m128i_i16[3] = 512;
    b.m128i_i16[4] = -32768;
    b.m128i_i16[5] = 32000;
    b.m128i_i16[6] = 0;
    b.m128i_i16[7] = -12;

    __m128i res = _mm_sign_epi16(a, b);

    printf_s("     a\t     b\t   res\n%6d\t%6d\t%6d\n%6d\t%6d\t%6d\n",
                a.m128i_i16[0], b.m128i_i16[0], res.m128i_i16[0],
                a.m128i_i16[1], b.m128i_i16[1], res.m128i_i16[1]);
    printf_s("%6d\t%6d\t%6d\n%6d\t%6d\t%6d\n%6d\t%6d\t%6d\n%6d\t%6d\t%6d\n",
                a.m128i_i16[2], b.m128i_i16[2], res.m128i_i16[2],
                a.m128i_i16[3], b.m128i_i16[3], res.m128i_i16[3],
                a.m128i_i16[4], b.m128i_i16[4], res.m128i_i16[4],
                a.m128i_i16[5], b.m128i_i16[5], res.m128i_i16[5]);
    printf_s("%6d\t%6d\t%6d\n%6d\t%6d\t%6d\n",
                a.m128i_i16[6], b.m128i_i16[6], res.m128i_i16[6],
                a.m128i_i16[7], b.m128i_i16[7], res.m128i_i16[7]);

    return 0;
}
     a       b     res
    42       1      42
 -3141       0       0
   128      -1    -128
 32000     512   32000
   -81  -32768      81
 -5421   32000   -5421
  -999       0       0
    25     -12     -25

See Also

Concepts

Compiler Intrinsics