Use intrinsics, if possible

This commit is contained in:
Adrian Conlon 2024-08-05 20:32:34 +01:00
parent bb6bcb9e70
commit 90c887d169
2 changed files with 9 additions and 25 deletions

View File

@ -56,40 +56,24 @@ namespace EightBit
public static int DemoteNibble(byte value) => HighNibble(value);
public static int CountBits(int value)
public static int CountBits(uint value)
{
var count = 0;
while (value != 0)
{
++count;
value &= value - 1;
}
return count;
return System.Numerics.BitOperations.PopCount(value);
}
public static int CountBits(byte value) => CountBits((int)value);
public static bool EvenParity(uint value)
{
return CountBits(value) % 2 == 0;
}
public static bool EvenParity(int value) => CountBits(value) % 2 == 0;
public static bool EvenParity(byte value) => EvenParity((int)value);
public static int FindFirstSet(int value)
public static int FindFirstSet(uint value)
{
if (value == 0)
{
return 0;
}
var test = 1;
var result = 1;
while ((value & test) == 0)
{
test <<= 1;
++result;
}
return result;
return System.Numerics.BitOperations.TrailingZeroCount(value) + 1;
}
}
}

View File

@ -66,7 +66,7 @@ namespace EightBit.GameBoy
var interruptEnable = this.Bus.Peek(IoRegisters.BASE + IoRegisters.IE);
var interruptFlags = this.bus.IO.Peek(IoRegisters.IF);
var masked = interruptEnable & interruptFlags;
var masked = (byte)(interruptEnable & interruptFlags);
if (masked != 0)
{
if (this.IME)