On 9 Nov 2014 08:40, "Maor via D.gnu" <d.gnu@puremagic.com> wrote:
>
> Hi,
>
> I'm trying to compile a program using inline asm with optimizations and I got my inline asm functions thrown out by the optimizer although I declared them as having side effects (by stating a memory clobber).
> I wrote the following toy program to demonstrate the problem:
>
> ----------------------------------------------
>
> import std.stdio;
> import gcc.attribute;
>
> @attribute("forceinline") ulong exchangeAndAdd(shared ulong *counter, ulong addition) {
> ulong retVal = void; // we don't want it initialized when dmd is used
> asm {
> "
> mov %2, %0 ;
> lock ;
> xadd %0, (%1) ;
> ":
> "=&r"(retVal) :
> "r"(counter), "r"(addition) :
Maybe try: "=m"(*counter)
The bug is likely in your input/output clobbers, gcc will always optimise against you unless you get the input/output/clobbers precisely correct.
Iain.