bits.h 833 B

123456789101112131415161718192021222324252627
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __LINUX_BITS_H
  3. #define __LINUX_BITS_H
  4. #include <asm/bitsperlong.h>
  5. #define BIT(nr) (1UL << (nr))
  6. #define BIT_ULL(nr) (1ULL << (nr))
  7. #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
  8. #define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
  9. #define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
  10. #define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
  11. #define BITS_PER_BYTE 8
  12. /*
  13. * Create a contiguous bitmask starting at bit position @l and ending at
  14. * position @h. For example
  15. * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
  16. */
  17. #define GENMASK(h, l) \
  18. (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
  19. #define GENMASK_ULL(h, l) \
  20. (((~0ULL) - (1ULL << (l)) + 1) & \
  21. (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
  22. #endif /* __LINUX_BITS_H */