Reputation: 11506
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);
In this case df
returns with zeros.
But if I do:
__m128 cA = _mm_set_ps1(2.0f);
__m128 cB = _mm_set_ps1(-2.0f);
__m128 df = _mm_cmpgt_ps(cA, cB);
It returns all -nan
.Is is expected behaviour? If it is,how do I evaluate those nans?
Using Intel CPU,MS VisualStudio 2017
Upvotes: 1
Views: 579
Reputation: 365667
SIMD compares produce a mask. All-one bits is the bit-pattern for -NaN
. All-zero bits is the bit-pattern for +0.0
They're not intended to be interpreted as float
. Use them with _mm_movemask_ps
, blends, or things like _mm_and_ps
.
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.
For more about how to use SIMD, look up a guide/tutorial. https://stackoverflow.com/tags/sse/info
Upvotes: 4