mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2025-03-08 06:32:06 +00:00
Use intrinsics, if possible
This commit is contained in:
parent
bb6bcb9e70
commit
90c887d169
@ -56,40 +56,24 @@ namespace EightBit
|
|||||||
|
|
||||||
public static int DemoteNibble(byte value) => HighNibble(value);
|
public static int DemoteNibble(byte value) => HighNibble(value);
|
||||||
|
|
||||||
public static int CountBits(int value)
|
public static int CountBits(uint value)
|
||||||
{
|
{
|
||||||
var count = 0;
|
return System.Numerics.BitOperations.PopCount(value);
|
||||||
while (value != 0)
|
|
||||||
{
|
|
||||||
++count;
|
|
||||||
value &= value - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 int FindFirstSet(uint value)
|
||||||
|
|
||||||
public static bool EvenParity(byte value) => EvenParity((int)value);
|
|
||||||
|
|
||||||
public static int FindFirstSet(int value)
|
|
||||||
{
|
{
|
||||||
if (value == 0)
|
if (value == 0)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var test = 1;
|
return System.Numerics.BitOperations.TrailingZeroCount(value) + 1;
|
||||||
var result = 1;
|
|
||||||
while ((value & test) == 0)
|
|
||||||
{
|
|
||||||
test <<= 1;
|
|
||||||
++result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ namespace EightBit.GameBoy
|
|||||||
var interruptEnable = this.Bus.Peek(IoRegisters.BASE + IoRegisters.IE);
|
var interruptEnable = this.Bus.Peek(IoRegisters.BASE + IoRegisters.IE);
|
||||||
var interruptFlags = this.bus.IO.Peek(IoRegisters.IF);
|
var interruptFlags = this.bus.IO.Peek(IoRegisters.IF);
|
||||||
|
|
||||||
var masked = interruptEnable & interruptFlags;
|
var masked = (byte)(interruptEnable & interruptFlags);
|
||||||
if (masked != 0)
|
if (masked != 0)
|
||||||
{
|
{
|
||||||
if (this.IME)
|
if (this.IME)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user