diff --git a/sys/compat/linuxkpi/common/include/linux/bitops.h b/sys/compat/linuxkpi/common/include/linux/bitops.h index 7ebb692ff172..a0d5be646c0b 100644 --- a/sys/compat/linuxkpi/common/include/linux/bitops.h +++ b/sys/compat/linuxkpi/common/include/linux/bitops.h @@ -35,6 +35,7 @@ #include #include #include +#include #define BIT(nr) (1UL << (nr)) #define BIT_ULL(nr) (1ULL << (nr)) @@ -43,6 +44,7 @@ #else #define BITS_PER_LONG 32 #endif + #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG)) #define BITMAP_LAST_WORD_MASK(n) (~0UL >> (BITS_PER_LONG - (n))) #define BITS_TO_LONGS(n) howmany((n), BITS_PER_LONG) @@ -51,6 +53,12 @@ #define GENMASK(h, l) (((~0UL) >> (BITS_PER_LONG - (h) - 1)) & ((~0UL) << (l))) #define BITS_PER_BYTE 8 +#define hweight8(x) bitcount((uint8_t)(x)) +#define hweight16(x) bitcount16(x) +#define hweight32(x) bitcount32(x) +#define hweight64(x) bitcount64(x) +#define hweight_long(x) bitcountl(x) + static inline int __ffs(int mask) { @@ -75,10 +83,15 @@ __flsl(long mask) return (flsl(mask) - 1); } +static inline int +fls64(uint64_t mask) +{ + return (flsll(mask)); +} + static inline uint32_t ror32(uint32_t word, unsigned int shift) { - return ((word >> shift) | (word << (32 - shift))); } @@ -542,4 +555,12 @@ bitmap_equal(const unsigned long *pa, return (1); } +static inline uint64_t +sign_extend64(uint64_t value, int index) +{ + uint8_t shift = 63 - index; + + return ((int64_t)(value << shift) >> shift); +} + #endif /* _LINUX_BITOPS_H_ */