[cairo] Speeding up _cairo_fixed_from_double

Jamey Sharp jamey at minilop.net
Mon Oct 30 16:31:13 PST 2006

On Mon, Oct 30, 2006 at 03:58:12PM -0500, Behdad Esfahbod wrote:
> Cannot reproduce.

That's what you get for compiling without -Wall. :-)

> This code:
> void
> main (void)

GCC optimized away the return statements and then the if, because you
declared main void. Change the return type to int and your first example

$ gcc -O -Wall -S a.c
	leal    4(%esp), %ecx
	andl    $-16, %esp
	pushl   -4(%ecx)
	pushl   %ebp
	movl    %esp, %ebp
	pushl   %ecx
	subl    $16, %esp
	movl    $1, -8(%ebp)
	cmpb    $1, -8(%ebp)
	sbbl    %eax, %eax
	andl    $-42, %eax
	addl    $108, %eax
	addl    $16, %esp
	popl    %ecx
	popl    %ebp
	leal    -4(%ecx), %esp

Which is obviously undesired and contains the same code I observed

Your example also differed from mine for two other reasons. GCC
apparently treats main differently from other functions, so just
renaming the function to 'a' produces:

	pushl   %ebp
	movl    %esp, %ebp
	subl    $16, %esp
	movl    $1, -4(%ebp)
	cmpb    $1, -4(%ebp)
	sbbl    %eax, %eax
	andl    $-42, %eax
	addl    $108, %eax

And, in order to observe only the interesting parts, I compiled my tests
with -fomit-frame-pointer. However this doesn't actually make much
difference on this example.

Anyway, Christoph Bauer mailed a much better version to me and the list
today, but it hasn't appeared on the list yet. I'd slightly edit his
version, so here's my take on it:

char endian(void)
	union { int i; char c; } e = { 1 };
	if ( e.c )
		return '\154'; /* 'l' */
		return '\102'; /* 'B' */

With frame pointer, this compiles to:

	pushl   %ebp
	movl    %esp, %ebp
	movl    $108, %eax
	popl    %ebp

And obviously -fomit-frame-pointer yields:

	movl    $108, %eax

And that compiles warning-free even with -Wall -ansi -pedantic. So
hooray for Christoph!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.freedesktop.org/archives/cairo/attachments/20061030/1b724432/attachment.pgp

More information about the cairo mailing list