* Another question re asm constraints
@ 2013-03-25 21:51 dw
2013-03-25 21:56 ` Ian Lance Taylor
0 siblings, 1 reply; 2+ messages in thread
From: dw @ 2013-03-25 21:51 UTC (permalink / raw)
To: gcc-help
Does specifying the + operator on outputs remove the need for listing
the variable as an input? For example:
__CRT_INLINE SHORT AddTest(SHORT *Addend)
{
SHORT ret = 1;
__asm__ __volatile__("lock\n\txaddw %0,%1 "
: "+r" (ret), "+m" (*Addend)
: "0" (ret)
: "cc");
return ret + 1;
}
Is the "0" constraint accomplishing anything useful here (such as
ensuring the 1 is in the register)? Or is it just advertising the fact
that I don't fully understand how constraints work?
And more importantly, is the "+m" enough to ensure that any existing
values for Addend have been written to memory? Or do I need to add "m"
(*Addend) as an input?
I've run some tests, and as best I can tell, neither input constraint is
required. But I don't rule out the possibility that that's just an
artifact of my test code. I can say for sure that "1" (*Addend) is the
wrong answer (compile error).
Thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Another question re asm constraints
2013-03-25 21:51 Another question re asm constraints dw
@ 2013-03-25 21:56 ` Ian Lance Taylor
0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2013-03-25 21:56 UTC (permalink / raw)
To: dw; +Cc: gcc-help
On Mon, Mar 25, 2013 at 2:51 PM, dw <limegreensocks@yahoo.com> wrote:
> Does specifying the + operator on outputs remove the need for listing the
> variable as an input? For example:
>
> __CRT_INLINE SHORT AddTest(SHORT *Addend)
> {
> SHORT ret = 1;
> __asm__ __volatile__("lock\n\txaddw %0,%1 "
> : "+r" (ret), "+m" (*Addend)
> : "0" (ret)
> : "cc");
> return ret + 1;
> }
>
> Is the "0" constraint accomplishing anything useful here
No.
> And more importantly, is the "+m" enough to ensure that any existing values
> for Addend have been written to memory?
Yes, at least from the compiler's perspective (there may be pending
writes from another processor that the compiler knows nothing about).
Ian
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-03-25 21:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-25 21:51 Another question re asm constraints dw
2013-03-25 21:56 ` Ian Lance Taylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).