How to negate (change sign) of the floating point elements in a __m128 type variable?

冷暖自知 提交于 2019-11-30 20:36:46

In practice your compiler should do a good job of generating the constant vector for 0.0. It will probably just use _mm_xor_ps, and if your code is in a loop it should hoist the constant generation out of the loop anyway. So, bottom line, use your original idea of:

v = _mm_sub_ps(_mm_set1_ps(0.0), v);

or another common trick, which is:

v = _mm_xor_ps(v, _mm_set1_ps(-0.0));

which just flips the sign bits instead of doing a subtraction (not quite as safe as the first method, since it doesn't do the right thing with NaNs, but may be more efficient in some cases).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!