diff --git a/ChangeLog b/ChangeLog index 808ca3a83..f5666bc33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2014-09-25 Alexei Podtelezhnikov + + [base] Avoid unnecessary long division. + + This applies to `FT_MulDiv' but not to `FT_DivFix', where overflows or + lack thereof are predicted accurately. + + * src/base/ftcalc.c (ft_div64by32): Improve readability. + (FT_MulDiv, FT_MulDiv_No_Round) [!FT_LONG64]: Use straight division + when multiplication stayed within 32 bits. + 2014-09-24 Werner Lemberg [autofit] Minor clean-ups. diff --git a/src/base/ftcalc.c b/src/base/ftcalc.c index be65a7aab..6a394773a 100644 --- a/src/base/ftcalc.c +++ b/src/base/ftcalc.c @@ -303,16 +303,14 @@ i = 32; do { - r <<= 1; q <<= 1; - r |= lo >> 31; + r = ( r << 1 ) | ( lo >> 31 ); lo <<= 1; /* left 64-bit shift */ if ( r >= y ) { r -= y; q |= 1; } - lo <<= 1; } while ( --i ); return q; @@ -416,7 +414,10 @@ temp2.hi = 0; temp2.lo = (FT_UInt32)(c >> 1); FT_Add64( &temp, &temp2, &temp ); - a = ft_div64by32( temp.hi, temp.lo, (FT_Int32)c ); + + /* last attempt to ditch long division */ + a = temp.hi == 0 ? temp.lo / c + : ft_div64by32( temp.hi, temp.lo, (FT_Int32)c ); } return ( s < 0 ? -a : a ); @@ -450,7 +451,10 @@ ft_multo64( (FT_Int32)a, (FT_Int32)b, &temp ); - a = ft_div64by32( temp.hi, temp.lo, (FT_Int32)c ); + + /* last attempt to ditch long division */ + a = temp.hi == 0 ? temp.lo / c + : ft_div64by32( temp.hi, temp.lo, (FT_Int32)c ); } return ( s < 0 ? -a : a );