Re: Trivial patch reducing fp mults in pango-cairo



On 12/9/06, Jorn Baayen <jorn openedhand com> wrote:
Hi,

Attached is a ridiculously simple patch cutting out two unnecessary FP
mults. It brings down __muldf3 by a few % in the profile (attached).

Good to know that I'm not alone in this pango/cairo/pangocairo FP battle :)

-        cffont->font_extents.y = - PANGO_UNITS ((font_extents.ascent + font_extents.descent) * 0.5);
+        cffont->font_extents.y = - PANGO_UNITS ((font_extents.ascent + font_extents.descent) / 2);

This one does look like a no brainer, as long as the change in
behavior is tolerable. Notice that the second version truncates the
intermediate integer result, while the first will hold on to some
precision through the intermediate double result. This difference is
perpetuated through the double mult and double add that follow in the
PANGO_UNITS macro. Thus, the expression as a whole will produce
different results for certain edge cases. These minor differences have
been the bane of my existence this past week with the recent
cairo_lround bugs that are due to very similiar circumstances.

-    size = pango_font_description_get_size (desc) / (1.*PANGO_SCALE);
+    size = pango_font_description_get_size (desc) / (double) PANGO_SCALE;

I'm surprised that the compiler doesn't perform this optimization
already. Hmmm...on mine the two versions produce identical code (even
without any optimization enabled).

$ gcc --version
sbox-arm-linux-gcc (GCC) 3.4.4 (release) (CodeSourcery ARM 2005q3-2)

Dan



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]