Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Use Arm64Base.LeadingZeroCount in BitOperations #26815

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics.X86;
using Arm64Base = System.Runtime.Intrinsics.Arm.Arm64.Base;

using Internal.Runtime.CompilerServices;

Expand Down Expand Up @@ -53,6 +54,10 @@ public static int LeadingZeroCount(uint value)
// LZCNT contract is 0->32
return (int)Lzcnt.LeadingZeroCount(value);
}
else if (Arm64Base.IsSupported)
{
return Arm64Base.LeadingZeroCount(value);
}

// Unguarded fallback contract is 0->31
if (value == 0)
Expand All @@ -77,6 +82,10 @@ public static int LeadingZeroCount(ulong value)
// LZCNT contract is 0->64
return (int)Lzcnt.X64.LeadingZeroCount(value);
}
else if (Arm64Base.IsSupported)
{
return Arm64Base.LeadingZeroCount(value);
}

uint hi = (uint)(value >> 32);

Expand Down