basic asm and memory clobbers

Andrew Haley aph@redhat.com
Fri Nov 20 10:17:00 GMT 2015


On 20/11/15 01:23, David Wohlferd wrote:
> I tried to picture the most basic case I can think of that uses 
> something clobber-able:
> 
>     for (int x=0; x < 1000; x++)
>        asm("#stuff");
> 
> This generates very simple and highly performant code:
> 
>          movl    $1000, %eax
> .L2:
>          #stuff
>          subl    $1, %eax
>          jne     .L2
> 
> Using extended asm to simulate the clobberall gives:
> 
>          movl    $1000, 44(%rsp)
> .L2:
>          #stuff
>          subl    $1, 44(%rsp)
>          jne     .L2
> 
> It allocates an extra 4 bytes, and changed everything to memory accesses 
> instead of using a register.

Can you show us your code?  I get

xx:
	movl	$1000, %eax
.L2:
	#stuff
	subl	$1, %eax
	jne	.L2
	rep; ret

for

void xx() {
  for (int x=0; x < 1000; x++)
    asm volatile("#stuff" : : : "memory");
}

What you're describing looks like a bug: x doesn't have its address
taken.

Andrew.



More information about the Gcc mailing list