Point72 / Point72/csp

Make bit counting operations constexpr on Windows using C++20 features

Open
#241 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

lang: c++ type: enhancement
Dominant language
Python
Stars
441
Forks
90
Avg merge
1d 12m
Merged PRs (30d)
5

Description

For Windows build support in https://github.com/Point72/csp/pull/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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the clz/ffs bit-counting operations and DynamicBitset, then inspect how the Windows MSVC intrinsics and the existing constexpr-control macro are selected. Check the C++20 support for std::bit_width and std::is_constant_evaluation. Done means the same functions remain constexpr on Windows while compiler intrinsics are used at runtime.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
operating-systems
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.