mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2026-10-24 14:05:42 +00:00
Performance changes (mainly for Z80)
This commit is contained in:
1 parent
9c7fa295b2
commit
552de802fe
2 files changed
+111
-13
No files matched your search
+49
-5
@@ -3,14 +3,28 @@
|
||||
// </copyright>
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace EightBit
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public sealed class Register16
|
||||
{
|
||||
// _low and _high must remain adjacent and in this order
|
||||
private byte _low;
|
||||
private byte _high;
|
||||
|
||||
// Whole overlays low/high as a single little-endian ushort.
|
||||
private ref ushort Whole
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
return ref Unsafe.As<byte, ushort>(ref this._low);
|
||||
}
|
||||
}
|
||||
|
||||
public Register16(byte low, byte high)
|
||||
{
|
||||
this.Low = low;
|
||||
@@ -47,11 +61,31 @@ namespace EightBit
|
||||
|
||||
public ushort Joined
|
||||
{
|
||||
get => Chip.MakeShort(this.Low, this.High);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
return this.Whole;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Chip.MakeShort(this.Low, this.High);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set
|
||||
{
|
||||
this.Low = Chip.LowByte(value);
|
||||
this.High = Chip.HighByte(value);
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
this.Whole = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Low = Chip.LowByte(value);
|
||||
this.High = Chip.HighByte(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,15 +121,25 @@ namespace EightBit
|
||||
this.High = high;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Assign(Register16 from)
|
||||
{
|
||||
Debug.Assert(from is not null, "from cannot be null");
|
||||
this.Low = from.Low;
|
||||
this.High = from.High;
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
this.Whole = from.Whole;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Low = from.Low;
|
||||
this.High = from.High;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Increment() => ++this.Joined;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Decrement() => --this.Joined;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user