git: 7cbc4d875971 - main - linuxkpi: Use `__builtin_popcountg()` instead of `bitcount*()`
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 09 Aug 2025 12:36:03 UTC
The branch main has been updated by dumbbell:
URL: https://cgit.FreeBSD.org/src/commit/?id=7cbc4d875971860d941cc15d7f42e6cfeffbfe66
commit 7cbc4d875971860d941cc15d7f42e6cfeffbfe66
Author: Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
AuthorDate: 2025-06-22 09:59:01 +0000
Commit: Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
CommitDate: 2025-08-09 12:26:25 +0000
linuxkpi: Use `__builtin_popcountg()` instead of `bitcount*()`
The DRM drivers generic code started to use `HWEIGHT64()` in the
definition of an array field in a structure. Therefore, the array size
needs to be known at compile time. This was not the case with the
`HWEIGHT*()` macros based on `bitcount*()`. The use of
`__builtin_popcountg()` solves that problem.
Reviewed by: bz
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D50995
---
sys/compat/linuxkpi/common/include/linux/bitops.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/sys/compat/linuxkpi/common/include/linux/bitops.h b/sys/compat/linuxkpi/common/include/linux/bitops.h
index bc776a0db9c4..00dd1f9a1ec0 100644
--- a/sys/compat/linuxkpi/common/include/linux/bitops.h
+++ b/sys/compat/linuxkpi/common/include/linux/bitops.h
@@ -62,10 +62,10 @@
#define hweight64(x) bitcount64(x)
#define hweight_long(x) bitcountl(x)
-#define HWEIGHT8(x) (bitcount8((uint8_t)(x)))
-#define HWEIGHT16(x) (bitcount16(x))
-#define HWEIGHT32(x) (bitcount32(x))
-#define HWEIGHT64(x) (bitcount64(x))
+#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)))
static inline int
__ffs(int mask)