Make bit counting operations constexpr on Windows using C++20 features
AdamGlustein opened this issue · comments
For Windows build support in #229, we remove the constexpr
specifier from the clz/ffs
bit counting operations as MSVC's _BitScanForward
and _BitScanReverse
compiler intrinsics are not constexpr, unlike gcc's __builtin_clz
and __builtin_ffs
. It also leads to a macro being defined to control whether the functions are marked constexpr or not in DynamicBitset.
However, using a combination of std::bit_width
in the new <bits>
header and std::is_constant_evaluation
we can make these functions constexpr for Windows too by only using the (faster) compiler intrinsics at runtime, not compile-time. It should make things a bit simpler and also ensures the same functions are constexpr across all platforms.