[FAST486]

Fix several bugs in Fast486RotateOperation.


svn path=/branches/ntvdm/; revision=60969
This commit is contained in:
Aleksandar Andrejevic 2013-11-13 02:38:36 +00:00
parent 677810ea95
commit c7de214d81

View file

@ -161,17 +161,17 @@ Fast486RotateOperation(PFAST486_STATE State,
UCHAR Count) UCHAR Count)
{ {
ULONG HighestBit = 1 << (Bits - 1); ULONG HighestBit = 1 << (Bits - 1);
ULONG MaxValue = HighestBit | (HighestBit - 1);
ULONG Result; ULONG Result;
/* Normalize the count */ /* Normalize the count */
Count &= 0x1F; Count &= 0x1F;
if (Operation <= 1) Count %= Bits;
else if (Operation <= 3) Count %= Bits + 1;
/* If the count is zero, do nothing */ /* If the count is zero, do nothing */
if (Count == 0) if (Count == 0) return Value;
{
Result = Value;
goto SetFlags;
}
/* Check which operation is this */ /* Check which operation is this */
switch (Operation) switch (Operation)
@ -205,14 +205,14 @@ Fast486RotateOperation(PFAST486_STATE State,
/* RCL */ /* RCL */
case 2: case 2:
{ {
Result = (Value << Count) Result = (Value << Count) | (State->Flags.Cf << (Count - 1));
| (State->Flags.Cf << (Count - 1))
| (Value >> (Bits - Count + 1)); /* Complete the calculation, but make sure we don't shift by too much */
if ((Bits - Count) < 31) Result |= Value >> (Bits - Count + 1);
/* Update CF and OF */ /* Update CF and OF */
State->Flags.Cf = ((Value & (1 << (Bits - Count))) != 0); State->Flags.Cf = ((Value & (1 << (Bits - Count))) != 0);
if (Count == 1) State->Flags.Of = State->Flags.Cf if (Count == 1) State->Flags.Of = State->Flags.Cf ^ ((Result & HighestBit) != 0);
^ ((Result & HighestBit) != 0);
break; break;
} }
@ -220,14 +220,16 @@ Fast486RotateOperation(PFAST486_STATE State,
/* RCR */ /* RCR */
case 3: case 3:
{ {
Result = (Value >> Count) /* Update OF */
| (State->Flags.Cf << (Bits - Count)) if (Count == 1) State->Flags.Of = State->Flags.Cf ^ ((Value & HighestBit) != 0);
| (Value << (Bits - Count + 1));
/* Update CF and OF */ Result = (Value >> Count) | (State->Flags.Cf << (Bits - Count));
State->Flags.Cf = ((Value & (1 << (Bits - Count))) != 0);
if (Count == 1) State->Flags.Of = State->Flags.Cf /* Complete the calculation, but make sure we don't shift by too much */
^ ((Result & (HighestBit >> 1)) != 0); if ((Bits - Count) < 31) Result |= Value << (Bits - Count + 1);
/* Update CF */
State->Flags.Cf = ((Value & (1 << (Count - 1))) != 0);
break; break;
} }
@ -274,11 +276,10 @@ Fast486RotateOperation(PFAST486_STATE State,
} }
} }
SetFlags:
if (Operation >= 4) if (Operation >= 4)
{ {
/* Update ZF, SF and PF */ /* Update ZF, SF and PF */
State->Flags.Zf = (Result == 0); State->Flags.Zf = ((Result & MaxValue) == 0);
State->Flags.Sf = ((Result & HighestBit) != 0); State->Flags.Sf = ((Result & HighestBit) != 0);
State->Flags.Pf = Fast486CalculateParity(Result); State->Flags.Pf = Fast486CalculateParity(Result);
} }