In a series of recent PRs (LZCNT, LOG2, TZCNT, ROTL/R, POPCNT) we consolidated and perf-tuned a basic set of bit-twiddling routines into a coreclrinternal static class.
The ask is to expose these methods as public in corefx (via ref assembly).
Rationale and Usage
Background & justification in the related issue https://github.com/dotnet/corefx/issues/32269 (which also proposes BT, BTS, BTR, BTC intrinsics)
Here is a brief summary to avoid reading the miles of comments there:
Duplicate implementations of the proposed functions were already implemented pervasively throughout the stack (coreclr, corert, corefx), often with different algorithms and certainly with different performance characteristics and little to no explicit test coverage.
Some existing callsites listed here
Some of the implementation had suboptimal performance or bugs.
These issues have been attended to, but the class is internal and so not easily available for consumption by downstream projects.
Scope
This issue is scoped to exposing just the existing methods.
There is no intent to add new signatures in this issue (unless required by api review)
Proposed API
Existing implementation here: BitOps.cs
namespaceSystem{
...publicstaticpartialclassBitOps{publicstaticintLeadingZeroCount(uintvalue){thrownull;}publicstaticintLeadingZeroCount(ulongvalue){thrownull;}publicstaticintLog2(uintvalue){thrownull;}publicstaticintLog2(ulongvalue){thrownull;}publicstaticintPopCount(uintvalue){thrownull;}publicstaticintPopCount(ulongvalue){thrownull;}publicstaticuintRotateLeft(uintvalue,intbitOffset){thrownull;}publicstaticulongRotateLeft(ulongvalue,intbitOffset){thrownull;}publicstaticuintRotateRight(uintvalue,intbitOffset){thrownull;}publicstaticulongRotateRight(ulongvalue,intbitOffset){thrownull;}publicstaticintTrailingZeroCount(intvalue){thrownull;}publicstaticintTrailingZeroCount(longvalue){thrownull;}publicstaticintTrailingZeroCount(uintvalue){thrownull;}publicstaticintTrailingZeroCount(ulongvalue){thrownull;}}
...}Details
The internal routines have already been implemented as follows:
- Centralized & standardized implementation of several intrinsics (LZCNT, LOG2, TZCNT, ROTL/R, POPCNT)
- Uses hardware intrinsics where possible
- Optimized software fallbacks
- Updated all known callsites in
coreclr - Added unit tests for all
BitOps methods (in corefx)
There are downstream callsites in corefx and corert as well as externals such as roslyn that would benefit from these intrinsics, as well as external (3rd party) projects.
cc @tannergooding, @jkotas
In a series of recent PRs (LZCNT, LOG2, TZCNT, ROTL/R, POPCNT) we consolidated and perf-tuned a basic set of bit-twiddling routines into a
coreclrinternal static class.The ask is to expose these methods as
publicincorefx(via ref assembly).Rationale and Usage
Background & justification in the related issue https://github.com/dotnet/corefx/issues/32269 (which also proposes
BT,BTS,BTR,BTCintrinsics)Here is a brief summary to avoid reading the miles of comments there:
Duplicate implementations of the proposed functions were already implemented pervasively throughout the stack (
coreclr,corert,corefx), often with different algorithms and certainly with different performance characteristics and little to no explicit test coverage.Some existing callsites listed here
Some of the implementation had suboptimal performance or bugs.
These issues have been attended to, but the class is
internaland so not easily available for consumption by downstream projects.Scope
This issue is scoped to exposing just the existing methods.
There is no intent to add new signatures in this issue (unless required by api review)
Proposed API
Existing implementation here: BitOps.cs
Details
The internal routines have already been implemented as follows:
coreclrBitOpsmethods (incorefx)There are downstream callsites in
corefxandcorertas well as externals such asroslynthat would benefit from these intrinsics, as well as external (3rd party) projects.cc @tannergooding, @jkotas