[cairo] Speeding up _cairo_fixed_from_double
Behdad Esfahbod
behdad at behdad.org
Mon Oct 30 12:58:12 PST 2006
On Mon, 2006-10-30 at 01:42 -0500, Jamey Sharp wrote:
> On Sun, Oct 29, 2006 at 08:12:48PM -0500, Jim Gettys wrote:
> > It should be. The man page refers to dead code elimination (dce) being
> > the default at -O or higher.
>
> Sadly, GCC isn't recognizing that as dead code, so it can't eliminate
> it. With -O, the version of GCC I tested [1] does some remarkable tricks
> to eliminate branches, but still checks endianness at runtime. I tested
> this C:
>
> int endian = 1;
> if (*(char *) &endian)
> return '\154'; /* 'l' */
> else
> return '\102'; /* 'B' */
>
> GCC produced this x86 assembly:
>
> movl $1, %eax
> movl %eax, 12(%esp)
> cmpb $1, 12(%esp)
> sbbl %eax, %eax
> andl $-42, %eax
> addl $108, %eax
>
> Impressive, but not what was desired.
>
> --Jamey
>
> [1] GCC: (GNU) 4.1.2 20060901 (prerelease) (Debian 4.1.1-13)
Cannot reproduce.
This code:
void
main (void)
{
int endian = 1;
if (*(char *) &endian)
return '\154'; /* 'l' */
else
return '\102'; /* 'B' */
}
generates:
$ gcc -O -S a.c
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
pushl %ebp
movl %esp, %ebp
pushl %ecx
popl %ecx
popl %ebp
leal -4(%ecx), %esp
ret
This code:
void
main (void)
{
return '\154'; /* 'l' */
}
generates:
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
pushl %ebp
movl %esp, %ebp
pushl %ecx
popl %ecx
popl %ebp
leal -4(%ecx), %esp
ret
(exactly the same as the previous one.)
and this code:
void
main (void)
{
volatile int endian = 1;
if (*(char *) &endian)
return '\154'; /* 'l' */
else
return '\102'; /* 'B' */
}
generates:
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
pushl %ebp
movl %esp, %ebp
pushl %ecx
subl $16, %esp
movl $1, -8(%ebp)
addl $16, %esp
popl %ecx
popl %ebp
leal -4(%ecx), %esp
ret
(this is exactly what I get if I compile the first code with -O0)
Without trying to understand what the generated code means, this
suggests that gcc is doing the right thing.
$ gcc --version
gcc (GCC) 4.1.1 20060525 (Red Hat 4.1.1-1)
--
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