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

Re: supression of 'matching constraint does not allow a register' warning


On Fri, Apr 30, 2004 at 09:23:35AM -0700, David Carlton wrote:
> I was wondering about that, too.  We have the following code in our
> system:
> 
>     __asm __volatile( "lock ; addl %1,%0" : "+m" (*p) : "ir" (v));
> 
> This worked with GCC 3.2.3; with 3.4.0, I get:
> 
>   warning: read-write constraint does not allow a register
> 
> Looking through the documentation, it seemed like the correct way to
> rewrite this is:
> 
>     __asm __volatile( "lock ; addl %2,%0" : "=m" (*p) : "0" (*p), "ir" (v));

This is a longhand way of writing the same thing you wrote above,
basically.

> (which is quite similar to what Peter says), but when I try to use
> that (code included after my .sig), I get:
> 
> foo.cpp:5: warning: matching constraint does not allow a register
> foo.cpp:5: warning: matching constraint does not allow a register
> foo.cpp:5: error: inconsistent operand constraints in an `asm'
> 
> Which is the same warning that Peter reports, plus an actual error.
> 
> Incidentally, is the error pointing at something wrong in the way I
> wrote the asm?  I don't know anything about extended asms, so I'm
> swimming in the dark here.  (I'm using x86 here.)

This has been discussed at length on this list :)  You can't have
matching constraints for memories.  Take a look at how libstdc++-v3
does this:
 
    __asm__ __volatile__ ("lock; add{l} {%1,%0|%0,%1}"
                          : "=m" (*__mem) : "ir" (__val), "m" (*__mem));

Er, except I'm not sure that's right; something was said about operands
unreferenced in the asm text being a bad idea.

-- 
Daniel Jacobowitz


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