Skip to content

Add constexpr to bit operations - #749

Merged
robambalu merged 8 commits into
Point72:mainfrom
AndrewSasmito:new-bit-windows
Aug 18, 2026
Merged

Add constexpr to bit operations#749
robambalu merged 8 commits into
Point72:mainfrom
AndrewSasmito:new-bit-windows

Conversation

@AndrewSasmito

Copy link
Copy Markdown
Contributor

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
@AndrewSasmito AndrewSasmito mentioned this pull request Aug 14, 2026
Signed-off-by: Andrew Sasmito <asasmito1920@gmail.com>
@AndrewSasmito

Copy link
Copy Markdown
Contributor Author

Tested the workflow on my personal fork, all tests are passing

@robambalu
robambalu merged commit decb441 into Point72:main Aug 18, 2026
31 checks passed
@AndrewSasmito
AndrewSasmito deleted the new-bit-windows branch August 18, 2026 19:02
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