Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flag Optimizations #222

Merged
merged 7 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions MBBSEmu.Tests/CPU/ADC_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MBBSEmu.CPU;
using System;
using MBBSEmu.Extensions;
using Xunit;

namespace MBBSEmu.Tests.CPU
Expand All @@ -17,7 +18,7 @@ public void ADC_AX_IMM16_CarryFlagSet(ushort adcValue, ushort axStartingValue, u
0x15, BitConverter.GetBytes(adcValue)[0], BitConverter.GetBytes(adcValue)[1]
});
mbbsEmuCpuRegisters.AX = axStartingValue;
mbbsEmuCpuRegisters.F.SetFlag(EnumFlags.CF);
mbbsEmuCpuRegisters.F = mbbsEmuCpuRegisters.F.SetFlag((ushort)EnumFlags.CF);

//Process Instruction
mbbsEmuCpuCore.Tick();
Expand All @@ -26,10 +27,10 @@ public void ADC_AX_IMM16_CarryFlagSet(ushort adcValue, ushort axStartingValue, u
Assert.Equal(axExpectedValue, mbbsEmuCpuRegisters.AX);

//Verify Flags
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.CF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.ZF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.OF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.SF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.CF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.ZF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.OF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.SF));
}

[Theory]
Expand All @@ -56,10 +57,10 @@ public void ADD_AX_IMM16_ADC_DX_IMM16(ushort addValue, ushort adcValue, ushort a
Assert.Equal(dxExpectedValue, mbbsEmuCpuRegisters.DX);

//Verify Flags
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.CF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.ZF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.OF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.SF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.CF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.ZF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.OF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.SF));
}
}
}
221 changes: 111 additions & 110 deletions MBBSEmu.Tests/CPU/ADD_Tests.cs

Large diffs are not rendered by default.

37 changes: 19 additions & 18 deletions MBBSEmu.Tests/CPU/CMP_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using MBBSEmu.CPU;
using MBBSEmu.Extensions;
using Xunit;

namespace MBBSEmu.Tests.CPU
{
public class CMP_Tests : CpuTestBase
{
[Theory]
[InlineData(0x0,0x0)]
[InlineData(0x0, 0x0)]
[InlineData(0x1, 0x1)]
public void CMP_AL_IMM8_ZeroFlag(byte alValue, byte sourceValue)
{
Expand All @@ -18,10 +19,10 @@ public void CMP_AL_IMM8_ZeroFlag(byte alValue, byte sourceValue)
mbbsEmuCpuCore.Tick();

//Verify Flags
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.CF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.ZF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.OF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.SF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.CF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.ZF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.OF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.SF));
}

[Theory]
Expand All @@ -36,14 +37,14 @@ public void CMP_AL_IMM8_CarryFlag(byte alValue, byte sourceValue)
mbbsEmuCpuCore.Tick();

//Verify Flags
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.CF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.ZF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.OF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.SF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.CF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.ZF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.OF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.SF));
}

[Theory]
[InlineData(0x2,0x1)]
[InlineData(0x2, 0x1)]
public void CMP_AL_IMM8_ClearFlags(byte alValue, byte sourceValue)
{
Reset();
Expand All @@ -54,10 +55,10 @@ public void CMP_AL_IMM8_ClearFlags(byte alValue, byte sourceValue)
mbbsEmuCpuCore.Tick();

//Verify Flags
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.CF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.ZF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.OF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.SF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.CF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.ZF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.OF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.SF));
}

[Theory]
Expand All @@ -72,10 +73,10 @@ public void CMP_AL_IMM8_CarryFlagSignFlag(byte alValue, byte sourceValue)
mbbsEmuCpuCore.Tick();

//Verify Flags
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.CF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.ZF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.OF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.SF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.CF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.ZF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.OF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.SF));
}
}
}
9 changes: 5 additions & 4 deletions MBBSEmu.Tests/CPU/CWD_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MBBSEmu.CPU;
using MBBSEmu.Extensions;
using Xunit;

namespace MBBSEmu.Tests.CPU
Expand All @@ -22,10 +23,10 @@ public void IDIV_AX_BX_ClearFlags(ushort axValue, ushort dxValue)
Assert.Equal(dxValue, mbbsEmuCpuRegisters.DX);

//Verify Flags
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.CF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.ZF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.OF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.SF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.CF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.ZF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.OF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.SF));
}
}
}
17 changes: 9 additions & 8 deletions MBBSEmu.Tests/CPU/JBE_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MBBSEmu.CPU;
using MBBSEmu.Extensions;
using Xunit;

namespace MBBSEmu.Tests.CPU
Expand All @@ -14,10 +15,10 @@ public void JBE_DoesJump(bool carryFlagValue, bool zeroFlagValue)
CreateCodeSegment(new byte[] { 0x76, 01 });

if(carryFlagValue)
mbbsEmuCpuRegisters.F.SetFlag(EnumFlags.CF);
mbbsEmuCpuRegisters.F = mbbsEmuCpuRegisters.F.SetFlag((ushort)EnumFlags.CF);

if(zeroFlagValue)
mbbsEmuCpuRegisters.F.SetFlag(EnumFlags.ZF);
mbbsEmuCpuRegisters.F = mbbsEmuCpuRegisters.F.SetFlag((ushort)EnumFlags.ZF);

//Process Instruction
mbbsEmuCpuCore.Tick();
Expand All @@ -28,24 +29,24 @@ public void JBE_DoesJump(bool carryFlagValue, bool zeroFlagValue)
//Verify Flags
if (carryFlagValue)
{
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.CF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.CF));
}
else
{
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.CF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.CF));
}

if (zeroFlagValue)
{
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.ZF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.ZF));
}
else
{
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.ZF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.ZF));
}

Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.OF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.SF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.OF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.SF));
}
}
}
17 changes: 9 additions & 8 deletions MBBSEmu.Tests/CPU/ROR_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Iced.Intel;
using System;
using MBBSEmu.Extensions;
using Xunit;
using static Iced.Intel.AssemblerRegisters;

Expand Down Expand Up @@ -35,8 +36,8 @@ public void ROR_AX_IMM16_CF_OF()
mbbsEmuCpuCore.Tick();

Assert.Equal(0x8000, mbbsEmuCpuRegisters.AX);
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet(MBBSEmu.CPU.EnumFlags.CF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet(MBBSEmu.CPU.EnumFlags.OF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)MBBSEmu.CPU.EnumFlags.CF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)MBBSEmu.CPU.EnumFlags.OF));
}

[Fact]
Expand All @@ -52,8 +53,8 @@ public void ROR_AX_IMM16_OF()
mbbsEmuCpuCore.Tick();

Assert.Equal(0x8000 >> 1, mbbsEmuCpuRegisters.AX);
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(MBBSEmu.CPU.EnumFlags.CF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet(MBBSEmu.CPU.EnumFlags.OF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)MBBSEmu.CPU.EnumFlags.CF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)MBBSEmu.CPU.EnumFlags.OF));
}

[Fact]
Expand Down Expand Up @@ -84,8 +85,8 @@ public void ROR_AL_IMM8_CF_OF()
mbbsEmuCpuCore.Tick();

Assert.Equal(0x80, mbbsEmuCpuRegisters.AX);
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet(MBBSEmu.CPU.EnumFlags.CF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet(MBBSEmu.CPU.EnumFlags.OF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)MBBSEmu.CPU.EnumFlags.CF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)MBBSEmu.CPU.EnumFlags.OF));
}

[Fact]
Expand All @@ -101,8 +102,8 @@ public void ROR_AL_IMM8_OF()
mbbsEmuCpuCore.Tick();

Assert.Equal(0x80 >> 1, mbbsEmuCpuRegisters.AX);
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(MBBSEmu.CPU.EnumFlags.CF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet(MBBSEmu.CPU.EnumFlags.OF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)MBBSEmu.CPU.EnumFlags.CF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)MBBSEmu.CPU.EnumFlags.OF));
}

[Fact]
Expand Down
17 changes: 9 additions & 8 deletions MBBSEmu.Tests/CPU/SHL_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Text;
using MBBSEmu.CPU;
using MBBSEmu.Extensions;
using Xunit;

namespace MBBSEmu.Tests.CPU
Expand All @@ -25,10 +26,10 @@ public void SHL_AX_CarryFlag_SignFlag(ushort axValue, ushort axExpectedValue)
Assert.Equal(axExpectedValue, mbbsEmuCpuRegisters.AX);

//Verify Flags
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.CF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.ZF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.OF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.SF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.CF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.ZF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.OF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.SF));
}

[Theory]
Expand All @@ -48,10 +49,10 @@ public void SHL_AX_OverflowFlag_SignFlag(ushort axValue, ushort axExpectedValue)
Assert.Equal(axExpectedValue, mbbsEmuCpuRegisters.AX);

//Verify Flags
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.CF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.ZF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.OF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet(EnumFlags.SF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.CF));
Assert.False(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.ZF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.OF));
Assert.True(mbbsEmuCpuRegisters.F.IsFlagSet((ushort)EnumFlags.SF));
}
}
}
Loading