Converting from __m128 to __m128i results in wrong value

ぃ、小莉子 提交于 2019-12-08 11:37:16

问题


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.


回答1:


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]



来源:https://stackoverflow.com/questions/30387531/converting-from-m128-to-m128i-results-in-wrong-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!