Skip to content

Commit

Permalink
Use runtime intrinsic to count leading zero (#3574)
Browse files Browse the repository at this point in the history
* Use runtime intrinsics to count leading zero

* Fix using order

* Add correct guard for using

* Exclude non-applicable tests

* Revert "Exclude non-applicable tests"

This reverts commit 6991fec.
  • Loading branch information
ThomsonTan committed Aug 16, 2022
1 parent d1da1d6 commit 28473bc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/OpenTelemetry/Internal/MathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
// </copyright>

using System.Diagnostics;
#if NETCOREAPP3_0_OR_GREATER
using System.Numerics;
#endif
using System.Runtime.CompilerServices;

namespace OpenTelemetry.Internal;
Expand Down Expand Up @@ -83,6 +86,9 @@ public static int LeadingZero32(int value)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int LeadingZero64(long value)
{
#if NETCOREAPP3_0_OR_GREATER
return BitOperations.LeadingZeroCount((ulong)value);
#else
unchecked
{
var high32 = (int)(value >> 32);
Expand All @@ -94,6 +100,7 @@ public static int LeadingZero64(long value)

return LeadingZero32((int)value) + 32;
}
#endif
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down

0 comments on commit 28473bc

Please sign in to comment.