Check XMM register for all zeroes

前端 未结 2 1200
面向向阳花
面向向阳花 2020-12-06 17:30

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

相关标签:
2条回答
  • 2020-12-06 18:12

    _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;
    }
    
    0 讨论(0)
  • 2020-12-06 18:25

    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.

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