[MPlayer-dev-eng] [PATCH] vf_ass: avoid a division
Nicolas George
nicolas.george at normalesup.org
Sun Sep 19 11:41:36 CEST 2010
Le jour de la Vertu, an CCXVIII, Reimar Döffinger a écrit :
> Performance should not really matter much there, since it's
> all the way outside the loop, so just writing it as
> *= 258
> would be fine.
> Using 258 has the advantage that the shifts in the inner loop
> are bytewise, for which a compiler can generate fast code
> even for architectures that do not have fast arbitrary shifts.
I tried various solutions and ended up with:
opacity = (0x10203 * opacity + 0x80) >> 8;
0x102.03 is a slightly better approximation of (1<<24)/(255*255) than
258=0x102, and the difference in speed with either "opacity += opacity<<7;
opacity <<=1" or "opacity *= 258" is below the standard deviation on ten
runs.
The attached version is bit-exact for about 99.97% of the values, and when
it is not, that's because it's rounding 0.498 upwards or 0.502 downwards.
I added comments to explain the magical numbers.
Regards,
--
Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mplayer-vfassnodiv-20100919.diff
Type: text/x-diff
Size: 1641 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20100919/cc359dcf/attachment.diff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20100919/cc359dcf/attachment.pgp>
More information about the MPlayer-dev-eng
mailing list