bitops.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef _BITOPS_H_
  2. #define _BITOPS_H_
  3. /*
  4. * Adapted from
  5. * include/linux/bitops.h
  6. *
  7. * Copyright (C) 2017, Red Hat Inc, Andrew Jones <drjones@redhat.com>
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2.
  10. */
  11. #define BITS_PER_LONG_LONG 64
  12. #define BIT(nr) (1UL << (nr))
  13. #define BIT_ULL(nr) (1ULL << (nr))
  14. #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
  15. #define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
  16. #define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
  17. #define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
  18. #define BITS_PER_BYTE 8
  19. #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
  20. #include <asm/bitops.h>
  21. /*
  22. * Create a contiguous bitmask starting at bit position @l and ending at
  23. * position @h. For example
  24. * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
  25. */
  26. #define GENMASK(h, l) \
  27. (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
  28. #define GENMASK_ULL(h, l) \
  29. (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
  30. #endif