0

I need to convert a float vector (__m128) to an integer vector (__m128i), and I am using _mm_cvtps_epi32, but I am not getting the expected value. Here is a very simple example:

__m128 test = _mm_set1_ps(4.5f);
__m128i test_i = _mm_cvtps_epi32(test);

The debugger output I get:

(lldb) po test
 ([0] = 4.5, [1] = 4.5, [2] = 4.5, [3] = 4.5)
(lldb) po test_i
 ([0] = 17179869188, [1] = 17179869188)
(lldb) 

As you can see, the resulting integer is.. 17179869188? From 4.5? And why are there only two values? _mm_cvtps_epi32 should convert 4 packed 32-bit floating-point values to 4 packed 32-bit integers.

Chris
  • 556
  • 1
  • 4
  • 18

1 Answers1

3

Debugger, in this example, interprets the __m128i value as two 64-bit integers, as opposed to four 32-bit ones expected by you. The actual conversion is correct.

In your code you need to explicitly specify how to interpret the SIMD value, for example: test_i.m128i_i32[0]

void_ptr
  • 618
  • 5
  • 15
  • Yep, that's what's happening. Also, just casting the result also works: `(int32_t)test_i[0]`. – Chris May 22 '15 at 11:22