From de0880752b81709771d2947bc763ffcd3995943b Mon Sep 17 00:00:00 2001 From: Aleksandar Andrejevic Date: Mon, 18 May 2015 12:17:40 +0000 Subject: [PATCH] [FAST486] Fix several division related problems: - In UnsignedDivMod128, fix the leading zero calculation for 128-bit numbers. - In Fast486FpuDivide, there's no need to increase the exponent by 64 (adding zeros at the end of a number after the decimal point changes nothing). - FDIV/FDIVR were reversed svn path=/trunk/; revision=67820 --- reactos/lib/fast486/fpu.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/reactos/lib/fast486/fpu.c b/reactos/lib/fast486/fpu.c index 78e64244a98..87ee330359f 100644 --- a/reactos/lib/fast486/fpu.c +++ b/reactos/lib/fast486/fpu.c @@ -203,9 +203,9 @@ UnsignedDivMod128(ULONGLONG DividendLow, * Calculate the number of significant bits the current * divisor has more than the original divisor */ - Bits = CountLeadingZeros64(Divisor) + 64; - Bits -= (CurrentHigh > 0ULL) ? CountLeadingZeros64(CurrentHigh) : 64; - Bits -= (CurrentLow > 0ULL) ? CountLeadingZeros64(CurrentLow) : 64; + Bits = CountLeadingZeros64(Divisor); + if (CurrentHigh > 0ULL) Bits -= CountLeadingZeros64(CurrentHigh); + else Bits -= CountLeadingZeros64(CurrentLow); if (Bits) { @@ -923,11 +923,10 @@ Fast486FpuDivide(PFAST486_STATE State, } /* Calculate the exponent of the result */ - Exponent = (LONG)FirstOperand->Exponent - (LONG)SecondOperand->Exponent - 64; + Exponent = (LONG)FirstOperand->Exponent - (LONG)SecondOperand->Exponent - 1; /* Divide the two mantissas */ Remainder = UnsignedDivMod128(0ULL, - /* Notice the 64 above - this is the high part */ FirstOperand->Mantissa, SecondOperand->Mantissa, &QuotientLow, @@ -1169,14 +1168,14 @@ Fast486FpuArithmeticOperation(PFAST486_STATE State, /* FDIV */ case 6: { - Fast486FpuDivide(State, DestOperand, SourceOperand, DestOperand); + Fast486FpuDivide(State, SourceOperand, DestOperand, DestOperand); break; } /* FDIVR */ case 7: { - Fast486FpuDivide(State, SourceOperand, DestOperand, DestOperand); + Fast486FpuDivide(State, DestOperand, SourceOperand, DestOperand); break; } }