aboutsummaryrefslogtreecommitdiff
path: root/ARMeilleure/Common/BitUtils.cs
diff options
context:
space:
mode:
Diffstat (limited to 'ARMeilleure/Common/BitUtils.cs')
-rw-r--r--ARMeilleure/Common/BitUtils.cs42
1 files changed, 3 insertions, 39 deletions
diff --git a/ARMeilleure/Common/BitUtils.cs b/ARMeilleure/Common/BitUtils.cs
index 7a29dcff..00fc6e5b 100644
--- a/ARMeilleure/Common/BitUtils.cs
+++ b/ARMeilleure/Common/BitUtils.cs
@@ -1,24 +1,13 @@
+using System.Numerics;
+
namespace ARMeilleure.Common
{
static class BitUtils
{
- private const int DeBrujinSequence = 0x77cb531;
-
- private static readonly int[] DeBrujinLbsLut;
-
private static readonly sbyte[] HbsNibbleLut;
static BitUtils()
{
- DeBrujinLbsLut = new int[32];
-
- for (int index = 0; index < DeBrujinLbsLut.Length; index++)
- {
- uint lutIndex = (uint)(DeBrujinSequence * (1 << index)) >> 27;
-
- DeBrujinLbsLut[lutIndex] = index;
- }
-
HbsNibbleLut = new sbyte[] { -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3 };
}
@@ -43,20 +32,7 @@ namespace ARMeilleure.Common
public static int HighestBitSet(int value)
{
- if (value == 0)
- {
- return -1;
- }
-
- for (int bit = 31; bit >= 0; bit--)
- {
- if (((value >> bit) & 1) != 0)
- {
- return bit;
- }
- }
-
- return -1;
+ return 31 - BitOperations.LeadingZeroCount((uint)value);
}
public static int HighestBitSetNibble(int value)
@@ -64,18 +40,6 @@ namespace ARMeilleure.Common
return HbsNibbleLut[value];
}
- public static int LowestBitSet(int value)
- {
- if (value == 0)
- {
- return -1;
- }
-
- int lsb = value & -value;
-
- return DeBrujinLbsLut[(uint)(DeBrujinSequence * lsb) >> 27];
- }
-
public static long Replicate(long bits, int size)
{
long output = 0;