Page MenuHomeFreeBSD

sys/bitcount.h: add __const_bitcount<n>
ClosedPublic

Authored by bz on Dec 18 2025, 10:51 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Jan 20, 6:24 PM
Unknown Object (File)
Tue, Jan 20, 9:31 AM
Unknown Object (File)
Thu, Jan 15, 7:07 PM
Unknown Object (File)
Sun, Jan 11, 12:08 AM
Unknown Object (File)
Sat, Jan 10, 4:05 PM
Unknown Object (File)
Sat, Jan 10, 4:46 AM
Unknown Object (File)
Wed, Jan 7, 4:44 PM
Unknown Object (File)
Tue, Jan 6, 3:11 PM
Subscribers

Details

Summary

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

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bz requested review of this revision.Dec 18 2025, 10:51 PM
bz created this revision.
bz added a subscriber: emaste.

Adding @emaste as I found @dumbbell 's version through the stack of local changes you carry.

LGTM. Out of paranoia, I verified using compiler explorer that it's reliably const enough to use in a macro even at -O0 with an old clang.

This revision is now accepted and ready to land.Dec 19 2025, 9:55 AM

LGTM. Out of paranoia, I verified using compiler explorer that it's reliably const enough to use in a macro even at -O0 with an old clang.

Neat tool. Didn't know about that. Thank you!

This revision was automatically updated to reflect the committed changes.