This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Inline assembler + register values


Konstantin Vladimirov schrieb:
Hi,

This problem is backend independent, so I build reproduction in x86
backend. Consider code:

int func(int x);

int test(int x, int *data)
{
  int retval;
  register int *buffer asm ("eax");

  buffer = data;
  retval = func(x);
  __asm__ __volatile__ (".internal_label _t." "4096"
                        ".%0.%1.%2:;nop"::"ri" (buffer), "ri" (4137), "ri" (4));
  return retval;
}

here nop will be replaced for something, that essentially uses %eax,
but it is not actually required for minimal reproduction.

being compiled with gcc (SUSE Linux) 4.5.0 20100604 [gcc-4_5-branch
revision 160292]

with following options:

gcc -m32 -O2 -S -fomit-frame-pointer reprox86.c

yields assembler:

  .type test, @function
test:
  subl  $28, %esp
  movl  32(%esp), %eax
  movl  %eax, (%esp)
  call  func                           // <--- here eax is clobbered
  .internal_label _t.4096.%eax.$4137.$4:;nop 0
  addl  $28, %esp
  ret

That looks quite odd. I have a question -- why compiler doesn't save &
restore buffer (i.e. %eax) value around function call, when we
specifically pointed to %eax usage in the inline assembler
instruction?

Thanks for responses in advance.

There was quite long discussion on the topic last August starting at http://gcc.gnu.org/ml/gcc/2011-08/msg00023.html with resonable conclusions like http://gcc.gnu.org/ml/gcc/2011-08/msg00067.html

I don't know what the current state of implementation is or if anyone is working on it or planned/plans to improve the matter.

Johann


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]