Share via


_mm_abs_epi8

Microsoft Specific

Emits the Supplemental Streaming SIMD Extensions 3 (SSSE3) instruction pabsb. This instruction returns the absolute value for each packed 8-bit integer of the 128-bit parameter.

__m128i _mm_abs_epi8( 
   __m128i a
);

Parameters

  • [in] a
    A 128-bit parameter that contains sixteen 8-bit signed integers for which the absolute values will be returned.

Return value

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

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

...

r15 := (a15 < 0) ? -a15 : a15

Requirements

Intrinsic

Architecture

_mm_abs_epi8

x86, x64

Header file <tmmintrin.h>

Remarks

The return value r and parameter a each consist of 128 bits. r0-r15, a0-a15 are the sequentially ordered 8-bit components of these parameters, where r0, a0 indicate the least significant 8 bits.

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

Example

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

int main()
{
    __m128i a;

    a.m128i_i8[0] = 0;
    a.m128i_i8[1] = 0;
    a.m128i_i8[2] = 2;
    a.m128i_i8[3] = -2;
    a.m128i_i8[4] = 15;
    a.m128i_i8[5] = -15;
    a.m128i_i8[6] = 127;
    a.m128i_i8[7] = -127;
    a.m128i_i8[8] = 64;
    a.m128i_i8[9] = -64;
    a.m128i_i8[10] = 27;
    a.m128i_i8[11] = -27;
    a.m128i_i8[12] = 90;
    a.m128i_i8[13] = -90;
    a.m128i_i8[14] = 0;
    a.m128i_i8[15] = 0;

    __m128i b = _mm_abs_epi8( a );

    printf_s("Original 8 bit pairs:\n%4d, %4d\n%4d, %4d\n%4d, %4d\n%4d, %4d\n",
        a.m128i_i8[0], a.m128i_i8[1], a.m128i_i8[2], a.m128i_i8[3],
        a.m128i_i8[4], a.m128i_i8[5], a.m128i_i8[6], a.m128i_i8[7]);
    printf_s("%4d, %4d\n%4d, %4d\n%4d, %4d\n%4d, %4d\n\n",
        a.m128i_i8[8], a.m128i_i8[9], a.m128i_i8[10], a.m128i_i8[11],
        a.m128i_i8[12], a.m128i_i8[13], a.m128i_i8[14], a.m128i_i8[15]);

    printf_s("New 8 bit pairs:\n%4d, %4d\n%4d, %4d\n%4d, %4d\n%4d, %4d\n",
        b.m128i_i8[0], b.m128i_i8[1], b.m128i_i8[2], b.m128i_i8[3],
        b.m128i_i8[4], b.m128i_i8[5], b.m128i_i8[6], b.m128i_i8[7]);
    printf_s("%4d, %4d\n%4d, %4d\n%4d, %4d\n%4d, %4d\n",
        b.m128i_i8[8], b.m128i_i8[9], b.m128i_i8[10], b.m128i_i8[11],
        b.m128i_i8[12], b.m128i_i8[13], b.m128i_i8[14], b.m128i_i8[15]);

    return 0;
}
Original 8 bit pairs:
   0,    0
   2,   -2
  15,  -15
 127, -127
  64,  -64
  27,  -27
  90,  -90
   0,    0

New 8 bit pairs:
   0,    0
   2,    2
  15,   15
 127,  127
  64,   64
  27,   27
  90,   90
   0,    0

See Also

Reference

Compiler Intrinsics