This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: RegRegname vs. Explicit Local Register Variables ...
- From: Matthijs van Duin <matthijs at cds dot nl>
- To: Magnus Fromreide <magfr at lysator dot liu dot se>
- Cc: Craig Newell <craign at ieee dot org>, <gcc at gcc dot gnu dot org>
- Date: Fri, 24 May 2002 12:36:45 +0200
- Subject: Re: RegRegname vs. Explicit Local Register Variables ...
- References: <Pine.GSO.4.33.0205241229270.27466-100000@proton.lysator.liu.se>
> > the solution was to make the variables "volatile register"
>
>Am I the only one that feels that this is the wrong approach?
No. But it was the only way I could get it to work.
>You can specify in the constraints for the asm expression that the
>variable should go into register a so there should be no need to do any of
>the tricks you are using.
Maybe it's a compiler bug, but this works:
template<class T> static inline T atomic_cas(volatile T& target, T
src, T dst) {
volatile register T foo asm("eax") = src;
asm volatile(
LOCK "cmpxchg %2,%0"
: "=m" (target), "=ir" (foo)
: "ir" (dst), "0" (target), "1" (foo)
);
return foo;
}
and without the "volatile" it doesn't. I've tried many things. The
problem is that by copy-propagation the "src" parameter gets filled
in directly into the asm inputs/outputs and return value, rather than
using %eax.
even stranger is that it thought that atomic_cas(target, src, dst)
== src while this is obviously not true. How can the optimizer think
that, when "foo" is marked as an output for my asm() block?
- xmath
Matthijs van Duin (NOTE: PGP key has changed!)
- PGP Key: 0x2D6F0BA7
- FP: 205D F7BA FFAD 9070 AB9E C5A8 BDB0 CA1B 2D6F 0BA7 -