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

Commit e2177ec

Browse files
committed
Move TrailingZeroCountFallback to common SpanHelpers
So it can be used by other types than byte
1 parent 0e8c1af commit e2177ec

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/System.Private.CoreLib/shared/System/SpanHelpers.Byte.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,18 +1244,5 @@ private static int LocateLastFoundByte(ulong match)
12441244
0x03ul << 32 |
12451245
0x02ul << 40 |
12461246
0x01ul << 48) + 1;
1247-
1248-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1249-
private static int TrailingZeroCountFallback(int matches)
1250-
{
1251-
// https://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup
1252-
return TrailingCountMultiplyDeBruijn[(int)(((uint)((matches & -matches) * 0x077CB531U)) >> 27)];
1253-
}
1254-
1255-
private static ReadOnlySpan<byte> TrailingCountMultiplyDeBruijn => new byte[32]
1256-
{
1257-
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
1258-
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
1259-
};
12601247
}
12611248
}

src/System.Private.CoreLib/shared/System/SpanHelpers.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Diagnostics;
66
using System.Globalization;
77
using System.Runtime;
8-
8+
using System.Runtime.CompilerServices;
99
using Internal.Runtime.CompilerServices;
1010

1111
#if BIT64
@@ -411,5 +411,18 @@ public static unsafe void ClearWithReferences(ref IntPtr ip, nuint pointerSizeLe
411411
// Write only element.
412412
ip = default;
413413
}
414+
415+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
416+
private static int TrailingZeroCountFallback(int matches)
417+
{
418+
// https://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup
419+
return TrailingCountMultiplyDeBruijn[(int)(((uint)((matches & -matches) * 0x077CB531U)) >> 27)];
420+
}
421+
422+
private static ReadOnlySpan<byte> TrailingCountMultiplyDeBruijn => new byte[32]
423+
{
424+
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
425+
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
426+
};
414427
}
415428
}

0 commit comments

Comments
 (0)