[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.
This commit is contained in:
parent
5b68e4fb60
commit
7f49111f81
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
2014-09-25 Alexei Podtelezhnikov <apodtele@gmail.com>
|
||||||
|
|
||||||
|
[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 <wl@gnu.org>
|
2014-09-24 Werner Lemberg <wl@gnu.org>
|
||||||
|
|
||||||
[autofit] Minor clean-ups.
|
[autofit] Minor clean-ups.
|
||||||
|
|
|
@ -303,16 +303,14 @@
|
||||||
i = 32;
|
i = 32;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
r <<= 1;
|
|
||||||
q <<= 1;
|
q <<= 1;
|
||||||
r |= lo >> 31;
|
r = ( r << 1 ) | ( lo >> 31 ); lo <<= 1; /* left 64-bit shift */
|
||||||
|
|
||||||
if ( r >= y )
|
if ( r >= y )
|
||||||
{
|
{
|
||||||
r -= y;
|
r -= y;
|
||||||
q |= 1;
|
q |= 1;
|
||||||
}
|
}
|
||||||
lo <<= 1;
|
|
||||||
} while ( --i );
|
} while ( --i );
|
||||||
|
|
||||||
return q;
|
return q;
|
||||||
|
@ -416,7 +414,10 @@
|
||||||
temp2.hi = 0;
|
temp2.hi = 0;
|
||||||
temp2.lo = (FT_UInt32)(c >> 1);
|
temp2.lo = (FT_UInt32)(c >> 1);
|
||||||
FT_Add64( &temp, &temp2, &temp );
|
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 );
|
return ( s < 0 ? -a : a );
|
||||||
|
@ -450,7 +451,10 @@
|
||||||
|
|
||||||
|
|
||||||
ft_multo64( (FT_Int32)a, (FT_Int32)b, &temp );
|
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 );
|
return ( s < 0 ? -a : a );
|
||||||
|
|
Loading…
Reference in New Issue