[smooth] Reduce shift in multiply-shift optimization.

* src/smooth/ftgrays.c (FT_UDIVPREP, FT_UDIV): Reduce shift.

Smaller shifts that keep the division operands of FT_UDIVPREP within
32 bits result in slightly faster divisions, which is noticeable in
the overall performance.  The loss of precision is tolerable until the
divisors (the components dx and dy) approach 32 - PIXEL_BITS. With
PIXEL_BITS = 8, this corresponds to 65,000 pixels or the bitmap size
that we refuse to render anyway.

Using `ftbench -p -s60 -t5 -bc timesi.ttf`,

Before: 8.52 us/op
After:  8.32 us/op
This commit is contained in:
Alexei Podtelezhnikov 2021-08-30 07:09:53 -04:00
parent d1c2000504
commit b6c11d494e
1 changed files with 4 additions and 6 deletions

View File

@ -387,11 +387,9 @@ typedef ptrdiff_t FT_PtrDist;
/* It should not exceed (64 - PIXEL_BITS) to prevent overflowing and */
/* leave enough room for 64-bit unsigned multiplication however. */
#define FT_UDIVPREP( c, b ) \
FT_Int64 b ## _r = c ? (FT_Int64)( ~(FT_UInt64)0 >> PIXEL_BITS ) / ( b ) \
: 0
FT_Int64 b ## _r = c ? (FT_Int64)0xFFFFFFFF / ( b ) : 0
#define FT_UDIV( a, b ) \
(TCoord)( ( (FT_UInt64)( a ) * (FT_UInt64)( b ## _r ) ) >> \
( sizeof( FT_UInt64 ) * FT_CHAR_BIT - PIXEL_BITS ) )
(TCoord)( ( (FT_UInt64)( a ) * (FT_UInt64)( b ## _r ) ) >> 32 )
/* Scale area and apply fill rule to calculate the coverage byte. */