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:		7cbc4d8759, 5e0a4859f2
MFC after:	3 days
Reviewed by:	brooks, emaste (without the sys/modules/Makefile change)
Differential Revision: https://reviews.freebsd.org/D54297
This commit is contained in:
Bjoern A. Zeeb
2025-09-15 23:52:13 +00:00
parent 27aa23cee8
commit 34892a8e30
2 changed files with 8 additions and 3 deletions
@@ -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)
-3
View File
@@ -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