ifilter_bitsum.h 601 B

1234567891011121314151617181920212223242526272829303132
  1. #ifdef EXPANDMASK
  2. #ifdef __GNUC__
  3. static IFT ifilter_bitsum(IFT x)
  4. {
  5. if (sizeof(IFT) == 16)
  6. return (((IFT) 1) <<
  7. (__builtin_popcountll((unsigned long long) (x >> (sizeof(IFT) * 8 / 2))) +
  8. __builtin_popcountll((unsigned long long) x))) - 1;
  9. if (sizeof(IFT) == 8)
  10. return (((IFT) 1) << __builtin_popcountll((unsigned long long) x)) - 1;
  11. return (((IFT) 1) << __builtin_popcount((unsigned int) x)) - 1;
  12. }
  13. #else // __GNUC__
  14. static IFT ifilter_bitsum(IFT x)
  15. {
  16. int v = 0;
  17. while (x != 0) {
  18. x &= x - 1;
  19. v++;
  20. }
  21. return (((IFT) 1) << v) - 1;
  22. }
  23. #endif // __GNUC__
  24. #endif // EXPANDMASK