How would one create a mask using SSE intrinsics which indicates whether the signs of two packed floats (__m128’s) are the same for example if comparing a and b where a is [1.0 -1.0 0.0 2.0] and b is [1.0 1.0 1.0 1.0] the desired mask we would get is [true false true true].
How would one create a mask using SSE intrinsics which indicates whether the signs
Share
Here’s one solution:
In this snippet, both
iandfwill have the same bitmask. I assume you want it in the__m128type so I added thef = _mm_castsi128_ps(i);to convert it back from an__m128i.Note that this code is sensitive to the sign of the zero. So
0.0and-0.0will affect the results.Explanations:
The way the code works is as follows: