33 lines
865 B
C
Executable File
33 lines
865 B
C
Executable File
#ifndef _MELIS_BITS_H_
|
|
#define _MELIS_BITS_H_
|
|
|
|
#define BITS_PER_LONG 32
|
|
#define BITS_PER_LONG_LONG 64
|
|
|
|
#ifndef BIT
|
|
#define BIT(nr) (1UL << (nr))
|
|
#endif
|
|
|
|
#define BIT_ULL(nr) (1ULL << (nr))
|
|
#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
|
|
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
|
|
#define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
|
|
#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
|
|
#define BITS_PER_BYTE 8
|
|
|
|
/*
|
|
* Create a contiguous bitmask starting at bit position @l and ending at
|
|
* position @h. For example
|
|
* GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
|
|
*/
|
|
#ifndef GENMASK
|
|
#define GENMASK(h, l) \
|
|
(((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
|
|
#endif
|
|
#define GENMASK_ULL(h, l) \
|
|
(((~0ULL) - (1ULL << (l)) + 1) & \
|
|
(~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
|
|
|
|
#endif /* _MELIS_BITS_H_ */
|
|
|