Share via


_mm_extract_epi8

Microsoft Specific

Emits the Streaming SIMD Extensions 4 (SSE4) instruction pextrb. This instruction extracts an 8-bit unsigned integer from a 128-bit parameter.

int _mm_extract_epi8( 
   __m128i a,
   const int ndx 
);

Parameters

  • [in] a
    A 128-bit parameter that contains sixteen 8-bit integers. These integers can be signed or unsigned.

  • [in] ndx
    A constant index that specifies the location of the value to extract.

Result value

The return value can be expressed by the following equation:

r := (ndx == 0) ? a0 :
   ((ndx == 1) ? a1 :
   ...
   ((ndx == 14) ? a14 : a15))

Requirements

Intrinsic

Architecture

_mm_extract_epi8

x86, x64

Header file <smmintrin.h>

Remarks

a0 - a15 are the individual 8-bit integers in parameter a, with a0 occupying the lowest 8 bits.

Only the least significant four bits of ndx are used.

The result is the unsigned equivalent of the appropriate 8-bits in parameter a.

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

Example

#include <stdio.h>
#include <smmintrin.h>

int main ()
{
    __m128i a;
    const int ndx1 = 4;
    const int ndx2 = 13;

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

    int res = _mm_extract_epi8(a, ndx1);
    printf_s("Result res should equal %d: %d\n", a.m128i_u8[ndx1], res);

    res = _mm_extract_epi8(a, ndx2);
    printf_s("Result res should equal %d: %d\n", a.m128i_u8[ndx2], res);

    return 0;
}
Result res should equal 16: 16
Result res should equal 224: 224

See Also

Reference

Compiler Intrinsics