arch_hweight.h 792 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. */
  7. #ifndef _ASM_ARCH_HWEIGHT_H
  8. #define _ASM_ARCH_HWEIGHT_H
  9. #ifdef ARCH_HAS_USABLE_BUILTIN_POPCOUNT
  10. #include <asm/types.h>
  11. static inline unsigned int __arch_hweight32(unsigned int w)
  12. {
  13. return __builtin_popcount(w);
  14. }
  15. static inline unsigned int __arch_hweight16(unsigned int w)
  16. {
  17. return __builtin_popcount(w & 0xffff);
  18. }
  19. static inline unsigned int __arch_hweight8(unsigned int w)
  20. {
  21. return __builtin_popcount(w & 0xff);
  22. }
  23. static inline unsigned long __arch_hweight64(__u64 w)
  24. {
  25. return __builtin_popcountll(w);
  26. }
  27. #else
  28. #include <asm-generic/bitops/arch_hweight.h>
  29. #endif
  30. #endif /* _ASM_ARCH_HWEIGHT_H */