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: RegRegname vs. Explicit Local Register Variables ...


>  > 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 -


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