You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BitOps.Log2(ulong) and BitOps.Log2(long) always smear the bits and index a De Bruijn table: six shift-or steps, a multiply, a shift and a table load. When the package compiles for .NET (Core 3.0 or later), System.Numerics.BitOperations.Log2 compiles to one lzcnt and an xor.
Evidence
DoxReloaded compiles these sources into a .NET 11 harness. Its board now finds the nearest button on a ray from the highest set bit of a 64-bit cell mask (BoardState.HighestSetBit). Under callgrind, BitOperations.Log2 inlined to or, lzcnt and xor, 3 instructions, where BitOps.Log2(long) runs about 14. That method calls BitOperations.Log2 under NET5_0_OR_GREATER and BitOps.Log2 otherwise.
Ask
Add a #if NETCOREAPP3_0_OR_GREATER branch to the Log2 overloads that calls System.Numerics.BitOperations.Log2, as #1285 did for PopCount and TrailingZeroCount. Keep the current code for Unity. BitOperations.Log2(0) returns 0, which matches the current contract.
Why
Then DoxReloaded can call BitOps.Log2 directly and delete its local branch.
Activity