Is there a way to check if all bits/bytes/words etc. in a __m128i variable are 0?
In my app I have to check if all integers packed in a in a __m128i variable are zeroes
_mm_testz_si128 is SSE4.1 which isn't supported on some CPUs (e.g. Intel Atom, AMD Phenom)
Here is an SSE2-compatible variant
inline bool isAllZeros(__m128i xmm) {
return _mm_movemask_epi8(_mm_cmpeq_epi8(xmm, _mm_setzero_si128())) == 0xFFFF;
}
Like Paul R commented to my original post:
"You don't need to initialise a dummy argument for the second parameter of PTEST, i.e. instead of _mm_testz_si128(idata, _mm_set1_epi32(0xFFFF)) you can just test a value against itself."
ptest does the entire job with one instruction.
This helped.