共用方式為


_mm_insert_epi32

Microsoft Specific

Emits the Streaming SIMD Extensions 4 (SSE4) instruction pinsrd. This instruction inserts a 32-bit integer into a 128-bit parameter.

__m128i _mm_insert_epi32( 
   __m128i a,
   int b,
   const int ndx 
);

Parameters

  • [in] a
    A 128-bit parameter that contains four 32-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
r2 := (ndx == 2) ? b : a2
r3 := (ndx == 3) ? b : a3

Requirements

Intrinsic

Architecture

_mm_insert_epi32

x86, x64

Header file <smmintrin.h>

Remarks

r0-r3 and a0-a3 are the sequentially ordered 32-bit components of return value r and parameter a. r0 and a0 are the least significant 32 bits.

Only the least significant 2 bits of ndx are interpreted.

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 = -65536;
    const int ndx = 2;

    a.m128i_i32[0] = 0;
    a.m128i_i32[1] = 11;
    a.m128i_i32[2] = 2222;
    a.m128i_i32[3] = 333333;

    __m128i res = _mm_insert_epi32(a, b, ndx);

    printf_s("Original a:\t%6d\t%6d\t%6d\t%6d\n\n",
                a.m128i_i32[0], a.m128i_i32[1], a.m128i_i32[2], a.m128i_i32[3]);

    printf_s("%d should be inserted into index %d.\n", b, ndx);
    printf_s("Result res:\t%6d\t%6d\t%6d\t%6d\n",
                res.m128i_i32[0], res.m128i_i32[1], res.m128i_i32[2], res.m128i_i32[3]);

    return 0;
}
Original a:          0      11    2222  333333

-65536 should be inserted into index 2.
Result res:          0      11  -65536  333333

See Also

Reference

Compiler Intrinsics