从__m128转换为__m128i会导致错误的值 [英] Converting from __m128 to __m128i results in wrong value

查看:383
本文介绍了从__m128转换为__m128i会导致错误的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将浮点向量(__m128)转换为整数向量(__m128i),并且我正在使用 _mm_cvtps_epi32 ,但未获得预期值。这是一个非常简单的示例:

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);

我得到的调试器输出:

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

如您所见,结果整数是.. 17179869188?从4.5开始?为什么只有两个值? _mm_cvtps_epi32 应该将4个压缩的32位浮点值转换为4个压缩的32位整数。

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.

推荐答案

调试器在此示例中,将 __ m128i 值解释为两个64位整数,而不是您期望的四个32位整数。实际的转换是正确的。

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.

在您的代码中,您需要明确指定如何解释SIMD值,例如: test_i.m128i_i32 [0]

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

这篇关于从__m128转换为__m128i会导致错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆