Author: aandrejevic
Date: Wed Nov 13 02:38:36 2013
New Revision: 60969
URL:
http://svn.reactos.org/svn/reactos?rev=60969&view=rev
Log:
[FAST486]
Fix several bugs in Fast486RotateOperation.
Modified:
branches/ntvdm/lib/fast486/opgroups.c
Modified: branches/ntvdm/lib/fast486/opgroups.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/lib/fast486/opgroups.c?re…
==============================================================================
--- branches/ntvdm/lib/fast486/opgroups.c [iso-8859-1] (original)
+++ branches/ntvdm/lib/fast486/opgroups.c [iso-8859-1] Wed Nov 13 02:38:36 2013
@@ -161,17 +161,17 @@
UCHAR Count)
{
ULONG HighestBit = 1 << (Bits - 1);
+ ULONG MaxValue = HighestBit | (HighestBit - 1);
ULONG Result;
/* Normalize the count */
Count &= 0x1F;
+ if (Operation <= 1) Count %= Bits;
+ else if (Operation <= 3) Count %= Bits + 1;
+
/* If the count is zero, do nothing */
- if (Count == 0)
- {
- Result = Value;
- goto SetFlags;
- }
+ if (Count == 0) return Value;
/* Check which operation is this */
switch (Operation)
@@ -205,9 +205,40 @@
/* RCL */
case 2:
{
- Result = (Value << Count)
- | (State->Flags.Cf << (Count - 1))
- | (Value >> (Bits - Count + 1));
+ Result = (Value << Count) | (State->Flags.Cf << (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 */
+ State->Flags.Cf = ((Value & (1 << (Bits - Count))) != 0);
+ if (Count == 1) State->Flags.Of = State->Flags.Cf ^ ((Result &
HighestBit) != 0);
+
+ break;
+ }
+
+ /* RCR */
+ case 3:
+ {
+ /* Update OF */
+ if (Count == 1) State->Flags.Of = State->Flags.Cf ^ ((Value &
HighestBit) != 0);
+
+ Result = (Value >> Count) | (State->Flags.Cf << (Bits -
Count));
+
+ /* Complete the calculation, but make sure we don't shift by too much */
+ if ((Bits - Count) < 31) Result |= Value << (Bits - Count + 1);
+
+ /* Update CF */
+ State->Flags.Cf = ((Value & (1 << (Count - 1))) != 0);
+
+ break;
+ }
+
+ /* SHL/SAL */
+ case 4:
+ case 6:
+ {
+ Result = Value << Count;
/* Update CF and OF */
State->Flags.Cf = ((Value & (1 << (Bits - Count))) != 0);
@@ -217,35 +248,6 @@
break;
}
- /* RCR */
- case 3:
- {
- Result = (Value >> Count)
- | (State->Flags.Cf << (Bits - Count))
- | (Value << (Bits - Count + 1));
-
- /* Update CF and OF */
- State->Flags.Cf = ((Value & (1 << (Bits - Count))) != 0);
- if (Count == 1) State->Flags.Of = State->Flags.Cf
- ^ ((Result & (HighestBit >> 1))
!= 0);
-
- break;
- }
-
- /* SHL/SAL */
- case 4:
- case 6:
- {
- Result = Value << Count;
-
- /* Update CF and OF */
- State->Flags.Cf = ((Value & (1 << (Bits - Count))) != 0);
- if (Count == 1) State->Flags.Of = State->Flags.Cf
- ^ ((Result & HighestBit) != 0);
-
- break;
- }
-
/* SHR */
case 5:
{
@@ -274,11 +276,10 @@
}
}
-SetFlags:
if (Operation >= 4)
{
/* Update ZF, SF and PF */
- State->Flags.Zf = (Result == 0);
+ State->Flags.Zf = ((Result & MaxValue) == 0);
State->Flags.Sf = ((Result & HighestBit) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
}