git: 34892a8e3005 - main - LinuxKPI: bitcount fix builds with gcc and older llvm
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 19 Dec 2025 21:23:55 UTC
The branch main has been updated by bz:
URL: https://cgit.FreeBSD.org/src/commit/?id=34892a8e30055000352d9612ad985be550c82bea
commit 34892a8e30055000352d9612ad985be550c82bea
Author: Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2025-09-15 23:52:13 +0000
Commit: Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2025-12-19 21:19:28 +0000
LinuxKPI: bitcount fix builds with gcc and older llvm
LLVM before 19 and gcc before 14 do not support __builtin_popcountg().
Use __const_bitcount<n> from sys/bitcount.h as a replacement in these
cases. This should still allow drm-kmod to build where the size needs
to be known at compile-time.
Remove the conditional for gcc around the iwlwifi modules build,
which was collateral damage in all this.
Sponsored by: The FreeBSD Foundation
Fixes: 7cbc4d875971, 5e0a4859f28a
MFC after: 3 days
Reviewed by: brooks, emaste (without the sys/modules/Makefile change)
Differential Revision: https://reviews.freebsd.org/D54297
---
sys/compat/linuxkpi/common/include/linux/bitops.h | 8 ++++++++
sys/modules/Makefile | 3 ---
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/sys/compat/linuxkpi/common/include/linux/bitops.h b/sys/compat/linuxkpi/common/include/linux/bitops.h
index a5a7abd55287..8fac80820f30 100644
--- a/sys/compat/linuxkpi/common/include/linux/bitops.h
+++ b/sys/compat/linuxkpi/common/include/linux/bitops.h
@@ -57,10 +57,18 @@
#define hweight64(x) bitcount64(x)
#define hweight_long(x) bitcountl(x)
+#if __has_builtin(__builtin_popcountg)
#define HWEIGHT8(x) (__builtin_popcountg((uint8_t)(x)))
#define HWEIGHT16(x) (__builtin_popcountg((uint16_t)(x)))
#define HWEIGHT32(x) (__builtin_popcountg((uint32_t)(x)))
#define HWEIGHT64(x) (__builtin_popcountg((uint64_t)(x)))
+#else
+/* LLVM before 19, gcc before 14. */
+#define HWEIGHT8(x) (__const_bitcount8((uint8_t)(x)))
+#define HWEIGHT16(x) (__const_bitcount16((uint16_t)(x)))
+#define HWEIGHT32(x) (__const_bitcount32((uint32_t)(x)))
+#define HWEIGHT64(x) (__const_bitcount64((uint64_t)(x)))
+#endif
static inline int
__ffs(int mask)
diff --git a/sys/modules/Makefile b/sys/modules/Makefile
index bf3588926acf..83099c5fff14 100644
--- a/sys/modules/Makefile
+++ b/sys/modules/Makefile
@@ -582,10 +582,7 @@ _mlx5ib= mlx5ib
_ena= ena
_gve= gve
_igc= igc
-# gcc13 and earlier lack __builtin_bitcountg used by linux emulation
-.if !(${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} < 140000)
_iwlwifi= iwlwifi
-.endif
_rtw88= rtw88
_rtw89= rtw89
_vmware= vmware