ref: 7f49111f81ac6082dbe5cee9e1147306bba4f27e
parent: 5b68e4fb60421038b58cceb8ef86e27ebf8625d7
author: Alexei Podtelezhnikov <[email protected]>
date: Thu Sep 25 18:54:38 EDT 2014
[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.
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2014-09-25 Alexei Podtelezhnikov <[email protected]>
+
+ [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 <[email protected]>
[autofit] Minor clean-ups.
--- a/src/base/ftcalc.c
+++ b/src/base/ftcalc.c
@@ -303,9 +303,8 @@
i = 32;
do
{
- r <<= 1;
q <<= 1;
- r |= lo >> 31;
+ r = ( r << 1 ) | ( lo >> 31 ); lo <<= 1; /* left 64-bit shift */
if ( r >= y )
{
@@ -312,7 +311,6 @@
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 );