[MPlayer-dev-eng] [PATCH] vf_ass: avoid a division
Reimar Döffinger
Reimar.Doeffinger at gmx.de
Sat Sep 18 15:08:57 CEST 2010
On Sat, Sep 18, 2010 at 01:09:21PM +0200, Nicolas George wrote:
> Le jour de la Vertu, an CCXVIII, Reimar Döffinger a écrit :
> > Go ahead (though note that may suggestion is to check the src before
> > instead of after the multiplication).
>
> It is indeed significantly faster (+7.4% instead of +3.6%). I must say that
> I am slightly disappointed with gcc's optimizations. And I am even more
> disappointed that declaring k outside of the loop makes a difference (+8.2%
> instead of +7.4%). (I had to change the declaration of k because "ISO C90
> forbids mixed declarations and code".)
Please don't move the declaration, we should not make the code
ugly for a compiler-specific optimization unless it is really important.
> @@ -317,7 +318,9 @@ static void my_draw_bitmap(struct vf_instance *vf, unsigned char *bitmap,
> dstv = vf->priv->planes[2] + dst_x + dst_y * vf->priv->outw;
> for (i = 0; i < bitmap_h; ++i) {
> for (j = 0; j < bitmap_w; ++j) {
> - unsigned k = ((unsigned) src[j]) * opacity / 255;
> + if (!src[j])
> + continue;
> + k = ((unsigned) src[j]) * opacity / 255;
And if you have a stupid compiler you really should write it the way I suggested:
unsigned k = src[j];
if (!k)
continue;
k = k * opacity / 255;
not only does it help make sure the compiler does not try to load it twice,
it also avoids the ugly cast.
But otherwise just apply it so we can move forward.
More information about the MPlayer-dev-eng
mailing list