On 03/28/2014 06:20 AM, dw wrote:
> Using this clobber causes the compiler to flush all (modified) registers 
> being used to store memory-based values to memory before executing the 
> @code{asm} statement.

I don't know what a "memory-based" value is.  This phrase doesn't help
at all.  In addition, it isn't true.  Modified registers are not
flushed to memory unless they are clobbered or their address is taken.
This sentence should be deleted.

Andrew.

int sum(int a[], int l) {
  int i;
  int sum = 0;
  for (i = 0; i < l; i++) {
    asm volatile("nop # Nothing at all":::"memory");
    sum += a[i];
  }
  return sum;
}


at -O2:


sum:
.LFB0:
        .cfi_startproc
        xorl    %eax, %eax
        testl   %esi, %esi
        jle     .L3
        subl    $1, %esi
        xorl    %edx, %edx
        leaq    4(,%rsi,4), %rcx
        .p2align 4,,10
        .p2align 3
.L4:
#APP
# 5 "z.c" 1
        nop # Nothing at all
# 0 "" 2
#NO_APP
        addl    (%rdi,%rdx), %eax
        addq    $4, %rdx
        cmpq    %rcx, %rdx
        jne     .L4
.L3:
        rep
        ret

Reply via email to