How does this function compute the absolute value of a float through a NOT and AND operation?

后端 未结 1 1364
感动是毒
感动是毒 2021-01-12 15:20

I am trying to understand how the following code snippet works. This program uses SIMD vector instructions (Intel SSE) to calculate the absolute value of 4 floats (so, basic

相关标签:
1条回答
  • 2021-01-12 15:36

    -0.0 is represented as 1000...0001. Therefore _mm_andnot_ps(-0.0, x)2 is equivalent to 0111...111 & x. This forces the MSB (which is the sign bit) to 0.


    1. In IEEE-754, at least.

    2. The _mm_andnot_ps intrinsic does not mean "NAND"; see e.g. http://msdn.microsoft.com/en-us/library/68h7wd02(v=vs.90).aspx.

    0 讨论(0)
提交回复
热议问题