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