[cairo] Optimize spans in the trapezoid rasterizer

Robert O'Callahan rocallahan at novell.com
Mon Jul 25 19:48:39 PDT 2005

On Mon, 2005-07-25 at 13:37 -0500, Billy Biggs wrote:
> Keith Packard (keithp at keithp.com):
> > On Sun, 2005-07-24 at 22:14 -0500, Billy Biggs wrote:
> > > The attached patch modifies the 8-bit alpha trapezoid rasterizer
> > > [...]
> > 
> > I note that the clip255 function includes a branch, while the normal
> > saturation function does not. I thought branches were "really bad"...
>   My understanding is that a branch at this level is no problem for
> modern processors.  I could not measure any difference on my G4 or P4.

It depends on whether the branch is predictable or not. Unpredictable
branches will kill performance, predictable branches are almost free.
"Predictable" basically means "the next value for the condition is
usually the same as the previous one".

For this particular piece of code, a good compiler/architecture will
actually use predicated execution/conditional moves to eliminate the
conditional branch, so that predictability no longer matters. In fact,
gcc -O2 turns your saturation statement into a CMOV on -mi686 or

> The code with the if statement is clearer, and we probably want a
> CPU-specific optimized version of the saturate loop anyway.



More information about the cairo mailing list