Implement more bit operation functions in the LinuxKPI.
Some minor whitespace nits while at it. Obtained from: kmacy @ MFC after: 1 week Sponsored by: Mellanox Technologies
This commit is contained in:
parent
522f4b2c75
commit
3cfeca84b4
@ -35,6 +35,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/libkern.h>
|
||||
|
||||
#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_ */
|
||||
|
Loading…
Reference in New Issue
Block a user