共用方式為


_mm_insert_ps

Microsoft Specific

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

__m128 _mm_insert_ps( 
   __m128 a,
   __m128 b,
   const int sel 
);

Parameters

  • [in] a
    A 128-bit parameter that contains four 32-bit floating point values.

  • [in] b
    A 128-bit parameter that contains four 32-bit floating point values.

  • [in] sel
    A constant that indicates which values to insert into the return value.

Result value

A 128-bit parameter that is a copy of the input parameter a, with a couple of exceptions. A value from b will be copied into an index indicated by sel. Also, sel may indicate that specific index values should be set to 0.

This can be expressed with the following equations:

sx := sel6-7
sval := (sx == 0) ? b0 : ((sx == 1) ? b1 : ((sx == 2) ? b2 : b3))

dx := sel4-5
r0 := (dx == 0) ? sval : a0
r1 := (dx == 1) ? sval : a1
r2 := (dx == 2) ? sval : a2
r3 := (dx == 3) ? sval : a3

zmask := sel0-3
r0 := (zmask0 == 1) ? +0.0 : r0
r1 := (zmask1 == 1) ? +0.0 : r1
r2 := (zmask2 == 1) ? +0.0 : r2
r3 := (zmask3 == 1) ? +0.0 : r3

Requirements

Intrinsic

Architecture

_mm_insert_ps

x86, x64

Header file <smmintrin.h>

Remarks

r0-r3, a0-a3, and b0-b3 are the sequentially ordered 32-bit components of return value r and parameters a and b, respectively. r0, a0, and b0 are the least significant 32 bits.

seli and zmaski denote bit i of parameter sel and temporary value zmask, with bit 0 being the least significant bit.

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

Example

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

int main ()
{
    __m128 a, b;
    const int sel = 0xD9;
    // The D means that b3 will be stored in r1
    // The 9 means that r0 and r3 will be set to 0

    a.m128_f32[0] = 1.0;
    a.m128_f32[1] = -1.0;
    a.m128_f32[2] = 1.5;
    a.m128_f32[3] = 105.5;
    b.m128_f32[0] = -5.0;
    b.m128_f32[1] = 10;
    b.m128_f32[2] = -325.0625;
    b.m128_f32[3] = 81.125;

    __m128 res = _mm_insert_ps(a, b, sel);

    printf_s("res0 should equal 0: %f\nres1 should equal %f: %f\n",
                res.m128_f32[0], b.m128_f32[3], res.m128_f32[1]);
    printf_s("res2 should equal %f: %f\nres3 should equal 0: %f\n",
                a.m128_f32[2], res.m128_f32[2], res.m128_f32[3]);

    return 0;
}
res0 should equal 0: 0.000000
res1 should equal 81.125000: 81.125000
res2 should equal 1.500000: 1.500000
res3 should equal 0: 0.000000

See Also

Reference

Compiler Intrinsics