From owner-svn-src-head@freebsd.org Mon Feb 27 14:38:18 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 97F37CEFC2B; Mon, 27 Feb 2017 14:38:18 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4D7FD661; Mon, 27 Feb 2017 14:38:18 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v1REcHjc015579; Mon, 27 Feb 2017 14:38:17 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v1REcHRQ015578; Mon, 27 Feb 2017 14:38:17 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201702271438.v1REcHRQ015578@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Mon, 27 Feb 2017 14:38:17 +0000 (UTC) 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 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Feb 2017 14:38:18 -0000 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 #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_ */