_mm_insert_epi8
Microsoft Specific
Emits the Streaming SIMD Extensions 4 (SSE4) instruction pinsrb. This instruction inserts an 8-bit integer into a 128-bit parameter.
__m128i _mm_insert_epi8(
__m128i a,
int b,
const int ndx
);
Parameters
[in] a
A 128-bit parameter that contains sixteen 8-bit integers.[in] b
An integer value.[in] ndx
A constant index value that specifies the location to insert.
Result value
The result is the same as the input parameter a, except for the value at index ndx. The value at the specified index is replaced with b. This can be expressed with the following equations:
r0 := (ndx == 0) ? b : a0
r1 := (ndx == 1) ? b : a1
...
r15 := (ndx == 15) ? b : a15
Requirements
Intrinsic |
Architecture |
---|---|
_mm_insert_epi8 |
x86, x64 |
Header file <smmintrin.h>
Remarks
r0-r15 and a0-a15 are the sequentially ordered 8-bit components of return value r and parameter a. r0 and a0 are the least significant 8 bits.
Only the lowest 8 bits of b are used.
Only the least significant 4 bits of ndx are used.
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;
int b = -32;
const int ndx = 7;
a.m128i_i8[0] = 0;
a.m128i_i8[1] = 1;
a.m128i_i8[2] = 2;
a.m128i_i8[3] = 3;
a.m128i_i8[4] = 4;
a.m128i_i8[5] = 5;
a.m128i_i8[6] = 6;
a.m128i_i8[7] = 7;
a.m128i_i8[8] = 8;
a.m128i_i8[9] = 9;
a.m128i_i8[10] = 10;
a.m128i_i8[11] = 11;
a.m128i_i8[12] = 12;
a.m128i_i8[13] = 13;
a.m128i_i8[14] = 14;
a.m128i_i8[15] = 15;
__m128i res = _mm_insert_epi8(a, b, ndx);
printf_s("Original a:\t%4d\t%4d\t%4d\t%4d\n\t\t%4d\t%4d\t%4d\t%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("\t\t%4d\t%4d\t%4d\t%4d\n\t\t%4d\t%4d\t%4d\t%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("%d should be inserted into index %d.\n", b, ndx);
printf_s("Result res:\t%4d\t%4d\t%4d\t%4d\n\t\t%4d\t%4d\t%4d\t%4d\n",
res.m128i_i8[0], res.m128i_i8[1], res.m128i_i8[2], res.m128i_i8[3],
res.m128i_i8[4], res.m128i_i8[5], res.m128i_i8[6], res.m128i_i8[7]);
printf_s("\t\t%4d\t%4d\t%4d\t%4d\n\t\t%4d\t%4d\t%4d\t%4d\n",
res.m128i_i8[8], res.m128i_i8[9], res.m128i_i8[10], res.m128i_i8[11],
res.m128i_i8[12], res.m128i_i8[13], res.m128i_i8[14], res.m128i_i8[15]);
return 0;
}
Original a: 0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
-32 should be inserted into index 7.
Result res: 0 1 2 3
4 5 6 -32
8 9 10 11
12 13 14 15