[MPlayer-dev-eng] icc benchmark

Trent Piepho xyzzy at speakeasy.org
Tue Jun 12 12:56:53 CEST 2007


On Tue, 12 Jun 2007, Uoti Urpala wrote:
>
> > Except for namespace polution: Is there another disadvantage with global
> > variables?

When building ELF shared libraries, non-static global variables require an
extra indirection to access (unless their visibility is changed from the
default).  They also make the dynamic symbol table larger and so slow down
dynamic linking.

There are also optimizations that gcc can do to static globals that it can't
do it non-static globals.

> That's a very big "except". Another reason to move from MANGLE to asm
> arguments is that almost all current uses of MANGLE are in fact unsafe.
> Each asm block must either read and write only the arguments given OR
> have "memory" in the globber list. Most of the asm blocks that currently

Even having "memory" in the clobber list isn't enough.  For example:

int x;
main() {
	int y;
	x = 1;
	// asm("mov x, %0" : "=r"(y)); 			// version A
	// asm("mov x, %0" : "=r"(y) : : "memory");	// version B
	// asm("mov %1, %0" : "=r"(y) : "m"(x));	// version C
	x = 2;
	printf("%d\n", y);
}

The asm statement is supposed to move the global "x" to the local y, and x is
supposed to be 1 when this happens.  This code should print 1, but what does
it do?
Version A, prints 2
Version B, prints 0
Version C, prints 1

The relevant asm code for A:
        movl    $2, x   #, x
        mov x, %eax     # y
        pushl   %eax    # y
        call    printf  #

gcc doesn't bother to set x to 1, since it thinks nothing used x between when
it's set to 1 and when it's set 2.

The relevant code for version B:
        mov x, %eax     # y
        movl    $2, x   #, x
        pushl   %eax    # y
        call    printf  #

In this case, because of the "memory" clobber, gcc sets x _after_ the asm
block.  The asm block could _write_ to x and modify it, so x can't be set to 2
before the block.  gcc still doesn't set x to 1 before the block, because it
still doesn't think the asm block can look at x.

Only version C works:
        movl    $1, x   #, x
        mov x, %eax     # x, y
        movl    $2, x   #, x
        pushl   %eax    # y
        call    printf  #

BTW, the reason gcc sets x to 2 even though nothing will use x, is because as
far as gcc knows printf could use x.



More information about the MPlayer-dev-eng mailing list