[cairo] Speeding up _cairo_fixed_from_double
jg at laptop.org
Sun Oct 29 12:56:40 PST 2006
This is at compile time, not at run time.
Any compiler worth it's salt these days does dead code analysis, and
drops the code that can never be executed.
In the sample here, one branch or the other is always dead code, and the
optimizer should be deleting it.
On Sun, 2006-10-29 at 15:48 -0500, Behdad Esfahbod wrote:
> 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
> > 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.
> > >
One Laptop Per Child
More information about the cairo