[cairo] Patches for speeding up _cairo_fixed_from_double
Pedro de Medeiros
pedrovmm+cairo-ml at gmail.com
Tue Nov 7 11:28:40 PST 2006
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;
}
==================================
(This little code is not endianness aware though.)
Cheers.
--
Pedro de Medeiros - Computer Science - University of Brasília
Home Page: http://www.nonseq.net - Linux User No.: 234250
More information about the cairo
mailing list