Author: aandrejevic
Date: Wed May 20 23:16:36 2015
New Revision: 67838
URL:
http://svn.reactos.org/svn/reactos?rev=67838&view=rev
Log:
[FAST486]
Fix a copy-paste bug. Adjust the number when subtracting in Fast486FpuAdd. Don't
overflow
the mantissa in Fast486FpuToSingle/Fast486FpuToDouble without correcting the exponent.
Modified:
trunk/reactos/lib/fast486/fpu.c
Modified: trunk/reactos/lib/fast486/fpu.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/fast486/fpu.c?rev=6783…
==============================================================================
--- trunk/reactos/lib/fast486/fpu.c [iso-8859-1] (original)
+++ trunk/reactos/lib/fast486/fpu.c [iso-8859-1] Wed May 20 23:16:36 2015
@@ -430,13 +430,13 @@
/* Calculate the remainder */
Remainder = Value->Mantissa & ((1ULL << 40) - 1);
+ /* Store the biased exponent */
+ *Result |= (ULONG)(UnbiasedExp + FPU_REAL4_BIAS) << 23;
+
/* Perform rounding */
Result64 = (ULONGLONG)*Result;
Fast486FpuRound(State, &Result64, Value->Sign, Remainder, 39);
*Result = (ULONG)Result64;
-
- /* Store the biased exponent */
- *Result |= (ULONG)(UnbiasedExp + FPU_REAL4_BIAS) << 23;
SetSign:
@@ -529,11 +529,11 @@
/* Calculate the remainder */
Remainder = Value->Mantissa & ((1 << 11) - 1);
+ /* Store the biased exponent */
+ *Result |= (ULONGLONG)(UnbiasedExp + FPU_REAL8_BIAS) << 52;
+
/* Perform rounding */
Fast486FpuRound(State, Result, Value->Sign, Remainder, 10);
-
- /* Store the biased exponent */
- *Result |= (ULONGLONG)(UnbiasedExp + FPU_REAL8_BIAS) << 52;
SetSign:
@@ -658,7 +658,7 @@
/* ... and the second one too */
if (SecondAdjusted.Exponent < TempResult.Exponent)
{
- if ((TempResult.Exponent - FirstAdjusted.Exponent) < 64)
+ if ((TempResult.Exponent - SecondAdjusted.Exponent) < 64)
{
SecondAdjusted.Mantissa >>= (TempResult.Exponent -
SecondAdjusted.Exponent);
SecondAdjusted.Exponent = TempResult.Exponent;
@@ -693,31 +693,64 @@
}
/* Did it overflow? */
- if (FPU_IS_NORMALIZED(&FirstAdjusted) &&
FPU_IS_NORMALIZED(&SecondAdjusted))
- {
- if (TempResult.Exponent == FPU_MAX_EXPONENT)
- {
- /* Raise the overflow exception */
- State->FpuStatus.Oe = TRUE;
-
- if (State->FpuControl.Om)
- {
- /* Total overflow, return infinity */
- TempResult.Mantissa = FPU_MANTISSA_HIGH_BIT;
- TempResult.Exponent = FPU_MAX_EXPONENT + 1;
+ if (FirstAdjusted.Sign == SecondAdjusted.Sign)
+ {
+ if (TempResult.Mantissa < FirstAdjusted.Mantissa
+ || TempResult.Mantissa < SecondAdjusted.Mantissa)
+ {
+ if (TempResult.Exponent == FPU_MAX_EXPONENT)
+ {
+ /* Raise the overflow exception */
+ State->FpuStatus.Oe = TRUE;
+
+ if (State->FpuControl.Om)
+ {
+ /* Total overflow, return infinity */
+ TempResult.Mantissa = FPU_MANTISSA_HIGH_BIT;
+ TempResult.Exponent = FPU_MAX_EXPONENT + 1;
+ }
+ else
+ {
+ Fast486FpuException(State);
+ return FALSE;
+ }
}
else
{
- Fast486FpuException(State);
- return FALSE;
- }
- }
- else
- {
- /* Lose the LSB in favor of the carry */
- TempResult.Mantissa >>= 1;
- TempResult.Mantissa |= FPU_MANTISSA_HIGH_BIT;
- TempResult.Exponent++;
+ /* Lose the LSB in favor of the carry */
+ TempResult.Mantissa >>= 1;
+ TempResult.Mantissa |= FPU_MANTISSA_HIGH_BIT;
+ TempResult.Exponent++;
+ }
+ }
+ }
+ else
+ {
+ if (TempResult.Mantissa >= FirstAdjusted.Mantissa
+ && TempResult.Mantissa >= SecondAdjusted.Mantissa)
+ {
+ if (TempResult.Exponent == 0)
+ {
+ /* Raise the underflow exception */
+ State->FpuStatus.Ue = TRUE;
+
+ if (State->FpuControl.Um)
+ {
+ /* Total overflow, return zero */
+ TempResult.Mantissa = 0ULL;
+ }
+ else
+ {
+ Fast486FpuException(State);
+ return FALSE;
+ }
+ }
+ else
+ {
+ /* Lose the MSB */
+ TempResult.Mantissa <<= 1;
+ TempResult.Exponent--;
+ }
}
}