SSE 比较返回 NAN 的向量 [英] SSE comparison returns vector of NANs
问题描述
我正在尝试这样的事情:
I am trying something like this:
__m128 cA = _mm_set_ps1(-2.0f);
__m128 cB = _mm_set_ps1(2.0f);
__m128 df = _mm_cmpgt_ps(cA, cB);
在这种情况下 df
返回零.
In this case df
returns with zeros.
但如果我这样做:
__m128 cA = _mm_set_ps1(2.0f);
__m128 cB = _mm_set_ps1(-2.0f);
__m128 df = _mm_cmpgt_ps(cA, cB);
它返回所有 -nan
.这是预期的行为吗?如果是,我如何评估这些nans?
It returns all -nan
.Is is expected behaviour? If it is,how do I evaluate those nans?
使用英特尔 CPU,MS VisualStudio 2017
Using Intel CPU,MS VisualStudio 2017
推荐答案
SIMD 比较产生掩码.全 1 位是 -NaN
的位模式.全零位是 +0.0
SIMD compares produce a mask. All-one bits is the bit-pattern for -NaN
. All-zero bits is the bit-pattern for +0.0
它们不应被解释为 float
.将它们与 _mm_movemask_ps
、混合或诸如 _mm_and_ps
之类的东西一起使用.
They're not intended to be interpreted as float
. Use them with _mm_movemask_ps
, blends, or things like _mm_and_ps
.
例如_mm_and_ps(vec, cmp_result)
将比较为假的元素归零.您可以使用它通过在添加之前将某些输入元素归零来执行条件添加.
e.g. _mm_and_ps( vec, cmp_result)
zeros the elements where the compare was false. You can use this to do a conditional add by zeroing some input elements before an add.
有关如何使用 SIMD 的更多信息,请查阅指南/教程.https://stackoverflow.com/tags/sse/info
For more about how to use SIMD, look up a guide/tutorial. https://stackoverflow.com/tags/sse/info
这篇关于SSE 比较返回 NAN 的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!