basic asm and memory clobbers

David Wohlferd dw@LimeGreenSocks.com
Fri Nov 20 10:38:00 GMT 2015


On 11/20/2015 2:17 AM, Andrew Haley wrote:
> 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.

The intent for 24414 is to change basic asm such that it will become 
(quoting jeff) "an opaque blob that read/write/clobber any register or 
memory location."  Such being the case, "memory" is not sufficient:

#define CLOBBERALL "eax", "ebx", "ecx", "edx", "r8", "r9", "r10", "r11", 
"r12", "r13", "r14", "r15", "edi", "esi", "ebp", "cc", "memory"

int main()
{
    for (int x=0; x < 1000; x++)
       asm("#":::CLOBBERALL);
}

dw



More information about the Gcc mailing list