<p dir="ltr"><br>
On 9 Nov 2014 08:40, "Maor via D.gnu" <<a href="mailto:d.gnu@puremagic.com">d.gnu@puremagic.com</a>> wrote:<br>
><br>
> Hi,<br>
><br>
> 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).<br>
> I wrote the following toy program to demonstrate the problem:<br>
><br>
> ----------------------------------------------<br>
><br>
> import std.stdio;<br>
> import gcc.attribute;<br>
><br>
> @attribute("forceinline") ulong exchangeAndAdd(shared ulong *counter, ulong addition) {<br>
> ulong retVal = void; // we don't want it initialized when dmd is used<br>
> asm {<br>
> "<br>
> mov %2, %0 ;<br>
> lock ;<br>
> xadd %0, (%1) ;<br>
> ":<br>
> "=&r"(retVal) :<br>
> "r"(counter), "r"(addition) :</p>
<p dir="ltr">Maybe try: "=m"(*counter)</p>
<p dir="ltr">The bug is likely in your input/output clobbers, gcc will always optimise against you unless you get the input/output/clobbers precisely correct.</p>
<p dir="ltr">Iain.</p>