bitops.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef _LINUX_BITOPS_H
  2. #define _LINUX_BITOPS_H
  3. #include <asm/types.h>
  4. /*
  5. * Include this here because some architectures need generic_ffs/fls in
  6. * scope
  7. */
  8. #include <asm/bitops.h>
  9. static __inline__ int get_bitmask_order(unsigned int count)
  10. {
  11. int order;
  12. order = fls(count);
  13. return order; /* We could be slightly more clever with -1 here... */
  14. }
  15. static __inline__ int get_count_order(unsigned int count)
  16. {
  17. int order;
  18. order = fls(count) - 1;
  19. if (count & (count - 1))
  20. order++;
  21. return order;
  22. }
  23. static inline unsigned long hweight_long(unsigned long w)
  24. {
  25. return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
  26. }
  27. /*
  28. * rol32 - rotate a 32-bit value left
  29. *
  30. * @word: value to rotate
  31. * @shift: bits to roll
  32. */
  33. static inline __u32 rol32(__u32 word, unsigned int shift)
  34. {
  35. return (word << shift) | (word >> (32 - shift));
  36. }
  37. /*
  38. * ror32 - rotate a 32-bit value right
  39. *
  40. * @word: value to rotate
  41. * @shift: bits to roll
  42. */
  43. static inline __u32 ror32(__u32 word, unsigned int shift)
  44. {
  45. return (word >> shift) | (word << (32 - shift));
  46. }
  47. static inline unsigned fls_long(unsigned long l)
  48. {
  49. if (sizeof(l) == 4)
  50. return fls(l);
  51. return fls64(l);
  52. }
  53. #endif