Skip to content

Add constexpr to bit operations - #749

Open
AndrewSasmito wants to merge 7 commits into
Point72:mainfrom
AndrewSasmito:new-bit-windows
Open

Add constexpr to bit operations#749
AndrewSasmito wants to merge 7 commits into
Point72:mainfrom
AndrewSasmito:new-bit-windows

Conversation

@AndrewSasmito

Copy link
Copy Markdown

Address #241

Re-opened PR with minimal changes to follow the current style

Summary

Restore constexpr support for the clz/ffs bit-counting operations on Windows.

Previously, Windows builds had to remove constexpr from these functions. This also required DynamicBitSet to conditionally mark functions as constexpr depending on the platform.

This change uses std::is_constant_evaluated() to select the appropriate implementation:

  • During constant evaluation, use the standard <bit> operations (std::countl_zero / std::countr_zero).
  • At runtime on Windows, continue using the MSVC bit-scan intrinsics for their performance.
  • Keep the existing compiler-builtin implementations on non-Windows platforms.

As a result, clz and ffs are consistently constexpr across platforms, and the platform-specific CLZ_CONSTEXPR macro can be removed from DynamicBitSet.

Signed-off-by: Andrew Sasmito <asasmito1920@gmail.com>
Signed-off-by: Andrew Sasmito <asasmito1920@gmail.com>
Comment thread cpp/csp/core/Platform.h Outdated
Signed-off-by: Andrew Sasmito <asasmito1920@gmail.com>
Signed-off-by: Andrew Sasmito <asasmito1920@gmail.com>
Comment thread cpp/csp/core/Platform.h Outdated
@AndrewSasmito
AndrewSasmito marked this pull request as draft August 14, 2026 15:18
Signed-off-by: Andrew Sasmito <asasmito1920@gmail.com>
@timkpaine timkpaine added type: enhancement Issues and PRs related to improvements to existing features lang: c++ Issues and PRs related to the C++ codebase part: tests Issues and PRs related to tests labels Aug 14, 2026
@AndrewSasmito
AndrewSasmito marked this pull request as ready for review August 14, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lang: c++ Issues and PRs related to the C++ codebase part: tests Issues and PRs related to tests type: enhancement Issues and PRs related to improvements to existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants