[cairo] Speeding up _cairo_fixed_from_double

Behdad Esfahbod behdad at behdad.org
Sun Oct 29 12:48:41 PST 2006


On Sun, 2006-10-29 at 14:04 -0500, Jim Gettys wrote:
> Evil endianness trick from Xlib:
> 
>         int endian = 1; 
> 
>         if (*(char *) &endian)
>             client.byteOrder = '\154'; /* 'l' */
>         else
>             client.byteOrder = '\102'; /* 'B' */
> 
> Even more fun about this, is that the compiler ends up optimizing
> exactly what you'd like; everything is determinable at compile time, so
> only the right assignment (or branch set of code) is emitted in the
> generated code.
> 
> I'll take this over the typical if-def's configure options, and other
> horrors any day.
> 
> Works fine when cross compiling too.

Right.  This is basically what the configure-time tests do.  The problem
with doing it runtime is that we sometimes need to define a macro
differently based on the endianness and that's not really easy to
implement using this snippet.  It works for the fixed_from_double case
at hand though.  Something no one mentioned in this thread is that cairo
already has endian-specific code.  So, no new non-portability is being
introduced.


behdad

>                              Regards,
>                                       - Jim
> 
> 
> If you don't succeed, try try again...  Was posting from an old address,
> got moderated to death, fixed the address, forgot to wait for the
> confirm, posted again, got moderated to death....
> 
> I guess no one deals with posting to the cairo list held for
> moderation....
> 
> 
> On Sun, 2006-10-29 at 13:00 -0500, Behdad Esfahbod wrote:
> > On Sun, 2006-10-29 at 10:21 -0500, Michael Sweet wrote:
> > > Jim Gettys wrote:
> > > > Evil endianness trick from Xlib:
> > >  > ...
> > > 
> > > I like it! :)
> > 
> > Care to share?  I don't think Jim's mail made it to the list.
> > 
-- 
behdad
http://behdad.org/

"Commandment Three says Do Not Kill, Amendment Two says Blood Will Spill"
        -- Dan Bern, "New American Language"



More information about the cairo mailing list