Skip to content

Add polyfills for System.Numerics.BitOperations - #137

Merged
Tyrrrz merged 5 commits into
primefrom
copilot/provide-polyfills-for-bitoperations
Aug 2, 2026
Merged

Add polyfills for System.Numerics.BitOperations#137
Tyrrrz merged 5 commits into
primefrom
copilot/provide-polyfills-for-bitoperations

Conversation

Copilot AI commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

BitOperations had no polyfill coverage. Its members were introduced across four different .NET versions, so a single guard wasn't enough — the type itself doesn't exist before .NET Core 3.0, with individual members added later.

Version breakdown

  • PolyShim/NetCore30/BitOperations.cs — defines the full type (PopCount, LeadingZeroCount, Log2, TrailingZeroCount, RotateLeft, RotateRight) for targets that predate .NET Core 3.0, since BitOperations isn't part of netstandard at any version either.
  • PolyShim/Net60/BitOperations.cs — adds IsPow2 and RoundUpToPowerOf2 via extension members.
  • PolyShim/Net70/BitOperations.cs — adds IntPtr/UIntPtr overloads of the above, matching the native nint/nuint overloads added that version.
  • PolyShim/Net80/BitOperations.cs — adds the Crc32C overloads.

Each file is guarded to only compile in when the corresponding native members aren't already available, following the same "define type, then extend via later directories" pattern already used for RandomNumberGenerator.

// Works uniformly regardless of target framework
BitOperations.PopCount(0b_1011u);       // .NET Core 3.0+
BitOperations.IsPow2(1024);             // .NET 6.0+
BitOperations.LeadingZeroCount((UIntPtr)1); // .NET 7.0+
BitOperations.Crc32C(0, (byte)0x42);    // .NET 8.0+

Other changes

  • Added BitOperationsTests.cs under the four corresponding PolyShim.Tests directories.
  • Regenerated Signatures.md to include the new type and members.

Copilot AI requested a review from Tyrrrz August 2, 2026 20:32
@Tyrrrz Tyrrrz added the enhancement New feature or request label Aug 2, 2026
@Tyrrrz
Tyrrrz marked this pull request as ready for review August 2, 2026 21:04
Comment thread PolyShim.Tests/Net60/BitOperationsTests.cs Outdated
@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.20%. Comparing base (24e0464) to head (e374b3f).

Additional details and impacted files
@@            Coverage Diff             @@
##            prime     #137      +/-   ##
==========================================
+ Coverage   99.17%   99.20%   +0.03%     
==========================================
  Files         150      154       +4     
  Lines        4005     4170     +165     
  Branches       88       89       +1     
==========================================
+ Hits         3972     4137     +165     
  Misses         13       13              
  Partials       20       20              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI requested a review from Tyrrrz August 2, 2026 21:08
@Tyrrrz

Tyrrrz commented Aug 2, 2026

Copy link
Copy Markdown
Owner

@copilot please merge latest prime and regenerate Signatures.md

Copilot AI commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please merge latest prime and regenerate Signatures.md

Merged prime and regenerated Signatures.md in b1da8c7/e374b3f.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants