Point72 / csp

csp is a high performance reactive stream processing library, written in C++ and Python

Home Page:https://github.com/Point72/csp/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.