On Mon, 1 Aug 2011, Georg-Johann Lay wrote:
> Michael Walle schrieb:
> > Hi list,
> >
> > consider the following test code:
> >  static void inline f1(int arg)
> >  {
> >    register int a1 asm("r8") = 10;
> >    register int a2 asm("r1") = arg;
> >
> >    asm("scall" : : "r"(a1), "r"(a2));
> >  }
> >
> >  void f2(int arg)
> >  {
> >    f1(arg >> 10);
> >  }
> >
> >
> > If you compile this code with 'lm32-gcc -O1 -S -c test.c' (see end of this
> > email), the a1 = 10; assignment is optimized away.
>
> Your asm has no output operands and no side effects, with more aggressive
> optimization the whole ask would disappear.

No, for the record that's not supposed to happen for asms
*without outputs*.

"If an @code{asm} has output operands, GCC assumes for
optimization purposes the instruction has no side effects except
to change the output
operands."

> What you want is maybe something like
>
>    asm volatile ("scall" : : "r"(a1), "r"(a2));

For the code at hand, the scall should be described to both have
an output and be marked volatile, since the system call is a
side effect that GCC can't see and might otherwise optimize away
if the system call return value is unused.  A plain volatile
marking as the above should not be necessary, modulo gcc bugs.

The real problem is quite worrysome.  I don't think a port
(lm32) should have to solve it with constraints; the (inline)
function parameter *should* cause a non-clobbering temporary to
hold any intermediate operations, but it looks as if you'll
otherwise have to debug it yourself.

brgds, H-P

Reply via email to