2

I am trying to use the result of a compare operation to add to an SSE variable. I have just realised that when using the _mm_cmplt_ps operation if the result is true it returns a NAN because 0xffffffff can't be represented which is of no use to me:

__m128 va;
__m128 vb;
__m128 result =_mm_set1_ps(0.0f);
vb = _mm_cmplt_ps(va,vb);
result = _mm_add_ps(result,vb);  // problem is that I would like to convert vb to 1.0's and 0.0's
Paul R
  • 208,748
  • 37
  • 389
  • 560
user1850254
  • 2,091
  • 3
  • 16
  • 17

1 Answers1

8

You can just apply the comparison mask to a vector of 1.0 values, e.g.

__m128  va, vb;
__m128  vcmp = _mm_cmplt_ps(va, vb);
__m128  vresult = _mm_and_ps(_mm_set1_ps(1.0f), vcmp);
Paul R
  • 208,748
  • 37
  • 389
  • 560
  • I would want the result to be a mixture of 1 .0 and 0.0 based on the value of the comparison? – user1850254 Apr 04 '13 at 11:04
  • `temp` is a mixture of 1.0s and 0.0s after it has been masked, so if that's all you need then omit the final addition. I've updated the code above now to reflect this. – Paul R Apr 04 '13 at 11:06