This is the mail archive of the gcc-help@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]

Another question re asm constraints


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.


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