From 94d8c8c4b2eed065a18f93e5747bb67b3bc93a86 Mon Sep 17 00:00:00 2001 From: Aleksandar Andrejevic Date: Tue, 19 May 2015 02:37:17 +0000 Subject: [PATCH] [FAST486] Fix UnsignedDivMod128 (again). Fix Fast486FpuAdd to handle numbers whose difference of exponents is greater than the number of bits in the mantissa. svn path=/trunk/; revision=67827 --- reactos/lib/fast486/fpu.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/reactos/lib/fast486/fpu.c b/reactos/lib/fast486/fpu.c index f84a926503d..9a21bd25b4f 100644 --- a/reactos/lib/fast486/fpu.c +++ b/reactos/lib/fast486/fpu.c @@ -204,9 +204,16 @@ UnsignedDivMod128(ULONGLONG DividendLow, * divisor has more than the original divisor */ Bits = CountLeadingZeros64(Divisor); - if (CurrentHigh > 0ULL) Bits -= CountLeadingZeros64(CurrentHigh); + if (CurrentHigh > 0ULL) Bits += 64 - CountLeadingZeros64(CurrentHigh); else Bits -= CountLeadingZeros64(CurrentLow); + if (Bits >= 64) + { + *QuotientHigh = *QuotientLow; + *QuotientLow = 0ULL; + Bits -= 64; + } + if (Bits) { /* Shift the quotient left by that amount */ @@ -635,15 +642,33 @@ Fast486FpuAdd(PFAST486_STATE State, /* Adjust the first operand to it... */ if (FirstAdjusted.Exponent < TempResult.Exponent) { - FirstAdjusted.Mantissa >>= (TempResult.Exponent - FirstAdjusted.Exponent); - FirstAdjusted.Exponent = TempResult.Exponent; + if ((TempResult.Exponent - FirstAdjusted.Exponent) < 64) + { + FirstAdjusted.Mantissa >>= (TempResult.Exponent - FirstAdjusted.Exponent); + FirstAdjusted.Exponent = TempResult.Exponent; + } + else + { + /* The second operand is the result */ + *Result = *SecondOperand; + return TRUE; + } } /* ... and the second one too */ if (SecondAdjusted.Exponent < TempResult.Exponent) { - SecondAdjusted.Mantissa >>= (TempResult.Exponent - SecondAdjusted.Exponent); - SecondAdjusted.Exponent = TempResult.Exponent; + if ((TempResult.Exponent - FirstAdjusted.Exponent) < 64) + { + SecondAdjusted.Mantissa >>= (TempResult.Exponent - SecondAdjusted.Exponent); + SecondAdjusted.Exponent = TempResult.Exponent; + } + else + { + /* The first operand is the result */ + *Result = *FirstOperand; + return TRUE; + } } if (FirstAdjusted.Sign == SecondAdjusted.Sign)