Date: Mon, 27 Feb 2017 14:38:17 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r314337 - head/sys/compat/linuxkpi/common/include/linux Message-ID: <201702271438.v1REcHRQ015578@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hselasky Date: Mon Feb 27 14:38:17 2017 New Revision: 314337 URL: https://svnweb.freebsd.org/changeset/base/314337 Log: 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 Modified: head/sys/compat/linuxkpi/common/include/linux/bitops.h Modified: head/sys/compat/linuxkpi/common/include/linux/bitops.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/bitops.h Mon Feb 27 13:59:02 2017 (r314336) +++ head/sys/compat/linuxkpi/common/include/linux/bitops.h Mon Feb 27 14:38:17 2017 (r314337) @@ -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_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201702271438.v1REcHRQ015578>