0

Suppose I have a 128-bit integer vector:

__m128i x;

Then how to know if all the bits in x are zeros?

Checking every packed integer is a simple approach.

But I'm looking for a faster way.

Is there any instruction in SSE can do this job?

KUN
  • 527
  • 4
  • 18

1 Answers1

3

If it is SSE 4.1, you can use _mm_testz_si128, e.g.

_mm_testz_si128(idata, _mm_set1_epi32(0x0000))

Probably look also into Check XMM register for all zeroes for a SSE2 compatible solution.

Community
  • 1
  • 1
Sebastian
  • 8,046
  • 2
  • 34
  • 58
  • 3
    Note that you don't need to generate a zero vector for the second param, you can just pass `idata` for both. – Paul R Jan 14 '15 at 14:21
  • Do you know how to do this for 256-bit float vector, that is , checking if all the bits in a 256-bit float vector are zero?@PaulR – KUN Jan 14 '15 at 14:38
  • 1
    @KUN come on, I am sure you can guess the name for 256 bits from the one for 128 bits... – Marc Glisse Jan 14 '15 at 18:06
  • As might be expected, you can just use the corresponding AVX intrinsic: `int _mm256_testz_ps (__m256 a, __m256 b)`. You might want to bookmark the [Intel intrinsics Guide](https://software.intel.com/sites/landingpage/IntrinsicsGuide/) for future such questions. – Paul R Jan 14 '15 at 18:52
  • But base on the description, _mm256_testz_ps (__m256 a, __m256 b) seems to check the sign bits after bitwise operation. What I want is checking all 256 bits.@PaulR – KUN Jan 15 '15 at 02:01
  • 1
    I was talking about _mm256_testz_si256... – Marc Glisse Jan 15 '15 at 23:58
  • My bad - I referenced `_mm256_testz_ps` when it should be `_mm256_testz_si128`. – Paul R Jan 16 '15 at 14:54