From 34a9f6128cc18c23ae0fed98b1e62925276960b3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Tigeot?= Date: Tue, 25 Aug 2015 07:15:27 +0200 Subject: [PATCH] kernel: Add bitcount64 to sys/systm.h Obtained-from: FreeBSD --- sys/sys/systm.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 2d9348fb2d..696dd62cc7 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -452,5 +452,18 @@ bitcount32(uint32_t x) return (x); } +static __inline uint64_t +bitcount64(uint64_t x) +{ + + x = (x & 0x5555555555555555) + ((x & 0xaaaaaaaaaaaaaaaa) >> 1); + x = (x & 0x3333333333333333) + ((x & 0xcccccccccccccccc) >> 2); + x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f; + x = (x + (x >> 8)); + x = (x + (x >> 16)); + x = (x + (x >> 32)) & 0x000000ff; + return (x); +} + #endif /* _KERNEL */ #endif /* !_SYS_SYSTM_H_ */ -- 2.11.4.GIT