Date: Fri, 16 Jan 2026 19:41:31 +0000 From: Bjoern A. Zeeb <bz@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 3fc5eb05910f - stable/14 - sys/bitcount.h: add __const_bitcount<n> Message-ID: <696a946b.de20.4b1ba44e@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/14 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=3fc5eb05910f0377e661c0ed57842baa1642b237 commit 3fc5eb05910f0377e661c0ed57842baa1642b237 Author: Bjoern A. Zeeb <bz@FreeBSD.org> AuthorDate: 2025-09-15 23:54:57 +0000 Commit: Bjoern A. Zeeb <bz@FreeBSD.org> CommitDate: 2026-01-16 19:37:55 +0000 sys/bitcount.h: add __const_bitcount<n> Add a version of __const_bitcount<n> which can be used to get the numbers at compile-time when __builtin_popcountg() is not available (see sys/compat/linuxkpi/common/include/linux/bitops.h for LLVM before 19 and gcc before 14). Obtained from: https://reviews.freebsd.org/D50995#1174884 by obiwac Sponsored by: The FreeBSD Foundation Reviewed by: brooks, emaste Differential Revision: https://reviews.freebsd.org/D54301 (cherry picked from commit 27aa23cee81088b0ffa974eec9f03c654c36438e) (cherry picked from commit 605389e40b938088718bd8aa75f4919884789927) --- sys/sys/bitcount.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/sys/sys/bitcount.h b/sys/sys/bitcount.h index aaa85c38d2e3..dfbba70f4d6a 100644 --- a/sys/sys/bitcount.h +++ b/sys/sys/bitcount.h @@ -41,6 +41,28 @@ #include <sys/_types.h> +#define __const_bitcount8(x) ( \ + !!((x) & (1 << 0)) + \ + !!((x) & (1 << 1)) + \ + !!((x) & (1 << 2)) + \ + !!((x) & (1 << 3)) + \ + !!((x) & (1 << 4)) + \ + !!((x) & (1 << 5)) + \ + !!((x) & (1 << 6)) + \ + !!((x) & (1 << 7))) + +#define __const_bitcount16(x) ( \ + __const_bitcount8(x) + \ + __const_bitcount8((x) >> 8)) + +#define __const_bitcount32(x) ( \ + __const_bitcount16(x) + \ + __const_bitcount16((x) >> 16)) + +#define __const_bitcount64(x) ( \ + __const_bitcount32(x) + \ + __const_bitcount32((x) >> 32)) + #ifdef __POPCNT__ #define __bitcount64(x) __builtin_popcountll((__uint64_t)(x)) #define __bitcount32(x) __builtin_popcount((__uint32_t)(x))home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?696a946b.de20.4b1ba44e>
