fls64.h 821 B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef _ASM_GENERIC_BITOPS_FLS64_H_
  2. #define _ASM_GENERIC_BITOPS_FLS64_H_
  3. #include <asm/types.h>
  4. /**
  5. * fls64 - find last set bit in a 64-bit word
  6. * @x: the word to search
  7. *
  8. * This is defined in a similar way as the libc and compiler builtin
  9. * ffsll, but returns the position of the most significant set bit.
  10. *
  11. * fls64(value) returns 0 if value is 0 or the position of the last
  12. * set bit if value is nonzero. The last (most significant) bit is
  13. * at position 64.
  14. */
  15. #if BITS_PER_LONG == 32
  16. static __always_inline int fls64(__u64 x)
  17. {
  18. __u32 h = x >> 32;
  19. if (h)
  20. return fls(h) + 32;
  21. return fls(x);
  22. }
  23. #elif BITS_PER_LONG == 64
  24. static __always_inline int fls64(__u64 x)
  25. {
  26. if (x == 0)
  27. return 0;
  28. return __fls(x) + 1;
  29. }
  30. #else
  31. #error BITS_PER_LONG not 32 or 64
  32. #endif
  33. #endif /* _ASM_GENERIC_BITOPS_FLS64_H_ */