Is an __m128i variable zero?

给你一囗甜甜゛ 提交于 2019-12-28 21:50:53

问题


How do I test if a __m128i variable has any nonzero value on SSE-2-and-earlier processors?


回答1:


In SSE2 you can do:

__m128i zero = _mm_setzero_si128();
if(_mm_movemask_epi8(_mm_cmpeq_epi32(x,zero)) == 0xFFFF)
{
    //the code...
}

this will test four int's vs zero then return a mask for each byte, so your bit-offsets of each corresponding int would be at 0, 4, 8 & 12, but the above test will catch if any bit is set, then if you preserve the mask you can work with the finer grained parts directly if need be.




回答2:


For the sake of completeness, with SSE4 one can use _mm_testz_si128.

const bool isAllZero = _mm_testz_si128(a,a);

Note that this is true when all bits are zero.



来源:https://stackoverflow.com/questions/7989897/is-an-m128i-variable-zero

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