Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.


Microsoft Specific

Generates the Convert Packed Doubleword Integers to Packed Single-Precision Floating-Point Values (cvtpi2ps) instruction, which converts the two packed 32-bit integers in b to single-precision floating-point values.

__m128 _mm_cvt_pi2ps( 
   __m128 a, 
   __m64 b 

[in] a

An __m128 structure containing four packed floating-point values.

[in] b

An __m64 structure containing two packed 32-bit integers.

An __m128 structure containing the result of the conversions as the first two elements; the third and fourth elements are copied from a.




x86 with SSE2

Header file <intrin.h>

The results are stored in the first two elements of the __m128 structure returned; the other two elements of the return value are copied from the high quadword of a. The __m128 structure represents an XMM register and the __m64 structure represents an MMX register, so the instruction generated does not involve system memory.

This routine is only available as an intrinsic.

// _mm_cvt_pi2ps.cpp
// processor: x86
#include <intrin.h>
#include <stdio.h>

#pragma intrinsic(_mm_cvt_pi2ps)

int main()
    __m128 a;
    __m64 b;

    // Aligned because you are using _mm_load_ps to load these
    // numbers into the XMM registers.
    __declspec(align(16)) float af[4] = { 100.5, 200.5,300.5, 400.5 };

    // Load a, which maps to the XMM registers, with the floating point
    //  values. _mm_load_ps requires a 16-byte aligned address.
    a = _mm_load_ps(af);

    // Load b with the two 32-bit signed integers.
    b = _mm_set_pi32(32, 33); 

    // Copy the ints in a to the lower floating point slots of b.
    a = _mm_cvt_pi2ps(a, b);

    // Use the EMMS instruction to signal the transition from XMM
    // registers to floating point registers (used to access the 
    // floating point values for printing to stdout).

    // Print out the values in a.
    printf_s("%lf %lf %lf %lf\n",
             a.m128_f32[0], a.m128_f32[1],
             a.m128_f32[2], a.m128_f32[3]);
33.000000 32.000000 300.500000 400.500000

Community Additions

© 2015 Microsoft