[cairo] Re: Speeding up _cairo_fixed_from_double
Nicholas Miell
nmiell at gmail.com
Mon Oct 30 16:10:31 PST 2006
On Mon, 30 Oct 2006 15:58:12 -0500, Behdad Esfahbod wrote:
> 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' */
> }
>
Try "int main(void)" instead of "void main(void)".
Compiling with -Wall helps, too. :)
And for little one-off tests like this, you shouldn't use main (on x86,
anyway -- gcc inserts extra stack alignment ops which confuses the issue).
More information about the cairo
mailing list