20#define BIT(_n) (1 << (_n))
21#define BIT64(_n) (1ULL << (_n))
24#define BIT_CLEAR(_var, _n) (_var &= ~BIT((_n)))
27#define BIT_SET(_var, _n) (_var |= BIT((_n)))
30#define BIT_READ(_x, _n) ((_x) & BIT((_n)))
32static inline uint64_t BIT_ENABLE(uint64_t bit,
unsigned int off,
int enable)
41static inline uint16_t __bswap_16(uint16_t x)
43 return (x << 8) | (x >> 8);
46static inline uint32_t __bswap_32(uint32_t x)
49 ((x & 0x0000FF00) << 8) |
50 ((x & 0x00FF0000) >> 8) |
54static inline uint64_t __bswap_64(uint64_t x)
57 ((x & 0x00FF000000000000ULL) >> 40) |
58 ((x & 0x0000FF0000000000ULL) >> 24) |
59 ((x & 0x000000FF00000000ULL) >> 8) |
60 ((x & 0x00000000FF000000ULL) << 8) |
61 ((x & 0x0000000000FF0000ULL) << 24) |
62 ((x & 0x000000000000FF00ULL) << 40) |
68#ifdef ARCH_LITTLE_ENDIAN
70#define htobe16(x) __bswap_16(x)
71#define htole16(x) (uint16_t)(x)
72#define be16toh(x) __bswap_16(x)
73#define le16toh(x) (uint16_t)(x)
75#define htobe32(x) __bswap_32(x)
76#define htole32(x) (uint32_t)(x)
77#define be32toh(x) __bswap_32(x)
78#define le32toh(x) (uint32_t)(x)
80#define htobe64(x) __bswap_64(x)
81#define htole64(x) (uint64_t)(x)
82#define be64toh(x) __bswap_64(x)
83#define le64toh(x) (uint64_t)(x)
87#define htobe16(x) (uint16_t)(x)
88#define htole16(x) __bswap_16(x)
89#define be16toh(x) (uint16_t)(x)
90#define le16toh(x) __bswap_16(x)
92#define htobe32(x) (uint32_t)(x)
93#define htole32(x) __bswap_32(x)
94#define be32toh(x) (uint32_t)(x)
95#define le32toh(x) __bswap_32(x)
97#define htobe64(x) (uint64_t)(x)
98#define htole64(x) __bswap_64(x)
99#define be64toh(x) (uint64_t)(x)
100#define le64toh(x) __bswap_64(x)
107 return __builtin_ctzl(word);
113 return (8 *
sizeof(word)) - __builtin_clzl(word) - 1;
119 return __builtin_ctzl(~word);
125 return (8 *
sizeof(word)) - __builtin_clzl(~word) - 1;
#define BIT_SET(_var, _n)
Set the nth bit.
Definition: bits.h:27
static ALWAYS_INLINE unsigned long bit_first_one(unsigned long word)
Find the index of the first set bit inside word.
Definition: bits.h:105
static ALWAYS_INLINE unsigned long bit_first_zero(unsigned long word)
Find the index of the first unset bit inside word.
Definition: bits.h:117
static ALWAYS_INLINE unsigned long bit_last_one(unsigned long word)
Find the index of the last set bit inside word.
Definition: bits.h:111
#define BIT_CLEAR(_var, _n)
Clear the nth bit.
Definition: bits.h:24
static ALWAYS_INLINE uint32_t bit_next_pow32(uint32_t val)
Compute the nex highest power of 2 for a 32bit integer.
Definition: bits.h:131
static ALWAYS_INLINE unsigned long bit_last_zero(unsigned long word)
Find the index of the last unset bit inside word.
Definition: bits.h:123