[cairo] Patches for speeding up _cairo_fixed_from_double

Daniel Amelang daniel.amelang at gmail.com
Thu Nov 16 14:38:03 PST 2006


On 11/7/06, Pedro de Medeiros <pedrovmm+cairo-ml at gmail.com> wrote:
> On 11/6/06, Behdad Esfahbod <behdad at behdad.org> wrote:
> > On Mon, 2006-11-06 at 15:49 -0800, Daniel Amelang wrote:
> > >
> > > > So, can you elaborate?  How and why does it fail?
> > >
> > > In single-precision mode, the new function returns zero for all input.
> > > This is because the large add that is performed overflows the FPU when
> > > it's only operating on 32-bits.
> >
> > Got it.  Thanks.
>
>
> A similar approach for single is possible, but losing precision,
> because the size of single and cairo_fixed_t are the same and there
> are exponent and signal bit, both being left out:
>
> ==================================
> #define CAIRO_MAGIC_NUMBER_FIXED_16_6 (196608.0)
>
> cairo_fixed_t
> _cairo_fixed_from_single(float f)
> {
>    union {
>       float f;
>       uint32_t n;
>    } u;
>
>    u.f = f + CAIRO_MAGIC_NUMBER_FIXED_16_6;
>
>    return (u.n & 0x3FFFFF) << 10;

Yah, I'd played with this too, but you'll notice that we lose 10 bits
on the end. I don't think Carl is OK with only 22 of the 32 bits
surviving the conversion, but only he can say.

Dan


More information about the cairo mailing list