Skip to content

Commit a2effc7

Browse files
committed
ARM64 intrinsic for TrailingZeroCount
1 parent 90be48c commit a2effc7

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/libraries/System.Private.CoreLib/src/System/Numerics/BitOperations.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ public static int TrailingZeroCount(uint value)
296296
return (int)Bmi1.TrailingZeroCount(value);
297297
}
298298

299+
if (ArmBase.IsSupported)
300+
{
301+
return (int)ArmBase.LeadingZeroCount(ArmBase.ReverseElementBits(value));
302+
}
303+
299304
// Unguarded fallback contract is 0->0
300305
if (value == 0)
301306
{
@@ -334,6 +339,10 @@ public static int TrailingZeroCount(ulong value)
334339
return (int)Bmi1.X64.TrailingZeroCount(value);
335340
}
336341

342+
if (ArmBase.Arm64.IsSupported)
343+
{
344+
return (int)ArmBase.Arm64.LeadingZeroCount(ArmBase.Arm64.ReverseElementBits(value));
345+
}
337346
uint lo = (uint)value;
338347

339348
if (lo == 0)

0 commit comments

Comments
 (0)