Skip to content

Commit

Permalink
Combine some SetFlags/ClearFlags calls. (#367)
Browse files Browse the repository at this point in the history
Should be faster then multiple calls.
  • Loading branch information
paladine authored Jan 5, 2021
1 parent dbe4013 commit 960218a
Showing 1 changed file with 22 additions and 52 deletions.
74 changes: 22 additions & 52 deletions MBBSEmu/CPU/CPUCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,7 @@ private void Op_Or()
};

//Clear Flags
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.CF);
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.OF);
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.CF | (ushort)EnumFlags.OF);

WriteToDestination(result);
}
Expand Down Expand Up @@ -1801,8 +1800,7 @@ private void Op_And()
WriteToDestination(result);

//Clear Flags
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.CF);
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.OF);
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.CF | (ushort)EnumFlags.OF);
}

[MethodImpl(CompilerOptimizations)]
Expand Down Expand Up @@ -1851,8 +1849,7 @@ private void Op_Xor()
WriteToDestination(result);

//Clear Flags
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.CF);
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.OF);
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.CF | (ushort)EnumFlags.OF);
}

[MethodImpl(CompilerOptimizations)]
Expand Down Expand Up @@ -2085,9 +2082,7 @@ private void Op_Test()
}

//Clear Overflow & Carry
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.OF);
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.CF);

Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.CF | (ushort)EnumFlags.OF);
}

[MethodImpl(CompilerOptimizations)]
Expand Down Expand Up @@ -2382,13 +2377,11 @@ private void Op_Mul_8()

if (result > byte.MaxValue)
{
Registers.F = Registers.F.SetFlag((ushort) EnumFlags.OF);
Registers.F = Registers.F.SetFlag((ushort)EnumFlags.CF);
Registers.F = Registers.F.SetFlag((ushort)EnumFlags.OF | (ushort)EnumFlags.CF);
}
else
{
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.OF);
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.CF);
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.CF | (ushort)EnumFlags.OF);
}
}

Expand All @@ -2403,13 +2396,11 @@ private void Op_Mul_16()

if (Registers.DX > 0)
{
Registers.F = Registers.F.SetFlag((ushort)EnumFlags.OF);
Registers.F = Registers.F.SetFlag((ushort)EnumFlags.CF);
Registers.F = Registers.F.SetFlag((ushort)EnumFlags.OF | (ushort)EnumFlags.CF);
}
else
{
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.OF);
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.CF);
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.CF | (ushort)EnumFlags.OF);
}
}

Expand All @@ -2424,13 +2415,11 @@ private void Op_Mul_32()

if (Registers.EDX > 0)
{
Registers.F = Registers.F.SetFlag((ushort)EnumFlags.OF);
Registers.F = Registers.F.SetFlag((ushort)EnumFlags.CF);
Registers.F = Registers.F.SetFlag((ushort)EnumFlags.OF | (ushort)EnumFlags.CF);
}
else
{
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.OF);
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.CF);
Registers.F = Registers.F.ClearFlag((ushort)EnumFlags.CF | (ushort)EnumFlags.OF);
}
}

Expand Down Expand Up @@ -2731,7 +2720,6 @@ private void Op_Fstsw()
[MethodImpl(CompilerOptimizations)]
private void Op_Sahf()
{

if (Registers.AH.IsFlagSet((byte)EnumFlags.SF))
{
Registers.F = Registers.F.SetFlag((ushort)EnumFlags.SF);
Expand Down Expand Up @@ -3272,28 +3260,22 @@ private void Op_Fcom()

if (double.IsNaN(ST0) || double.IsNaN(source))
{
Registers.Fpu.SetFlag(EnumFpuStatusFlags.Code0);
Registers.Fpu.SetFlag(EnumFpuStatusFlags.Code2);
Registers.Fpu.SetFlag(EnumFpuStatusFlags.Code3);
Registers.Fpu.SetFlag(EnumFpuStatusFlags.Code0 | EnumFpuStatusFlags.Code2 | EnumFpuStatusFlags.Code3);
return;
}

if (ST0 > source)
{
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code0);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code2);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code3);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code0 | EnumFpuStatusFlags.Code2 | EnumFpuStatusFlags.Code3);
}
else if (ST0 < source)
{
Registers.Fpu.SetFlag(EnumFpuStatusFlags.Code0);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code2);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code3);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code2 | EnumFpuStatusFlags.Code3);
}
else
{
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code0);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code2);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code0 | EnumFpuStatusFlags.Code2);
Registers.Fpu.SetFlag(EnumFpuStatusFlags.Code3);
}
}
Expand Down Expand Up @@ -3324,28 +3306,22 @@ private void Op_Fcompp()

if (double.IsNaN(ST0) || double.IsNaN(ST1))
{
Registers.Fpu.SetFlag(EnumFpuStatusFlags.Code0);
Registers.Fpu.SetFlag(EnumFpuStatusFlags.Code2);
Registers.Fpu.SetFlag(EnumFpuStatusFlags.Code3);
Registers.Fpu.SetFlag(EnumFpuStatusFlags.Code0 | EnumFpuStatusFlags.Code2 | EnumFpuStatusFlags.Code3);
}
else
{
if (ST0 > ST1)
{
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code0);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code2);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code3);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code0 | EnumFpuStatusFlags.Code2 | EnumFpuStatusFlags.Code3);
}
else if (ST0 < ST1)
{
Registers.Fpu.SetFlag(EnumFpuStatusFlags.Code0);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code2);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code3);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code2 | EnumFpuStatusFlags.Code3);
}
else
{
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code0);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code2);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code0 | EnumFpuStatusFlags.Code2);
Registers.Fpu.SetFlag(EnumFpuStatusFlags.Code3);
}
}
Expand Down Expand Up @@ -3504,28 +3480,22 @@ private void Op_Ftst()

if (double.IsNaN(ST0Value))
{
Registers.Fpu.SetFlag(EnumFpuStatusFlags.Code0);
Registers.Fpu.SetFlag(EnumFpuStatusFlags.Code2);
Registers.Fpu.SetFlag(EnumFpuStatusFlags.Code3);
Registers.Fpu.SetFlag(EnumFpuStatusFlags.Code0 | EnumFpuStatusFlags.Code2 | EnumFpuStatusFlags.Code3);
return;
}

if (ST0Value > 0.0d)
{
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code0);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code2);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code3);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code0 | EnumFpuStatusFlags.Code2 | EnumFpuStatusFlags.Code3);
}
else if (ST0Value < 0.0d)
{
Registers.Fpu.SetFlag(EnumFpuStatusFlags.Code0);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code2);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code3);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code2 | EnumFpuStatusFlags.Code3);
}
else
{
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code0);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code2);
Registers.Fpu.ClearFlag(EnumFpuStatusFlags.Code0 | EnumFpuStatusFlags.Code2);
Registers.Fpu.SetFlag(EnumFpuStatusFlags.Code3);
}

Expand Down

0 comments on commit 960218a

Please sign in to comment.