This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: matching constraints in asm operands question
On Tue, Mar 01, 2005 at 11:50:04PM -0500, Peter Barada wrote:
>
> >> which seems to work, but I'm really concerned about the manuals
> >> warning of the input and output operads being in seperate places.
> >>
> >> Which form is correct?
> >
> >static __inline__ void atomic_inc(atomic_t *v)
> >{
> > __asm__ __volatile__("addql #1,%0" : "+m" (*v));
> >}
> >
> >Works just fine, every where I know of. It is the same as you last
> >example also.
>
> Ugh, in the hopes of simplifying the example, I made it somewhat trivial...
>
> static __inline__ void atomic_add(atomic_t *v, int i)
> {
> __asm__ __volatile__("addl %2,%0" : "=m" (*v) : "m" (*v), "d" (i));
> }
>
> Is that correct? And if so, then isn't the documentation wrong?
This is correct, as is a version using "+m" (*v) : "d"(i),
though of course the %2 gets moved to %1 in that case.
Using "m" multiple times is correct because "m" specifies a specific
address, and the compiler cannot change the address. It can change
the *form* of the address (%a0 vs 20(%a0,%d1*4), etc), but that's a
different prospect.
r~