[cairo] Speeding up _cairo_fixed_from_double
Behdad Esfahbod
behdad at behdad.org
Sun Oct 29 13:14:42 PST 2006
On Sun, 2006-10-29 at 15:56 -0500, Jim Gettys wrote:
> 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.
Right. But it's compile-time just because of the optimization. Maybe
what I really mean is that it's compile-time, not preprocessor-time. So
you cannot define a NATIVE_TO_NET_ORDER(x) macro using it easily.
behdad
> - Jim
>
>
> 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
> > 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