On 11/22/2011 10:55 AM, Bodart, Mitch L wrote:
> What aspect of inline asm processing is preventing gcc from allocating
> register eax to both %0 and %1's address in the following test case?
>
> gcc -m32 -S foo.c
> foo.c: In function 'foo':
> foo.c:20: error: can't find a register in class 'GENERAL_REGS' while
> reloading 'asm'
>
> I could understand this error if val was an early clobber, "=&r" (val),
> as the description of "&" says such operands cannot be assigned to the
> same register as an input, or any register used in a memory address.
> But since no ampersand is present, it seems eax is available here
> for both operands.
>
> int foo(int *ptr) {
> int val;
>
> __asm__ __volatile__("junk %0, %1"
> : "=r" (val), "+m" (*ptr)
%1 is also an output operand (+), which means its address needs to be
available as an output address reload. This will conflict with normal
output reloads.
I think I know what you are trying to write: %1 as a RW memory, but
the address is latched on input; %0 as an independent output.
You could try writing this as
: "=r"(val), "=X"(*ptr) : "m"(*ptr)
instead. Untested, so there might be other gotchas...
r~