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, 30 Apr 2004 12:10:27 -0400 (EDT), Peter Barada <peter@the-baradas.com> said:

> In the Linux-2.4.x kernel for m68k, the atomic operations use the
> addql/subql instructions for incrementing/decrementing atomic
> variables, and force the variables to memory to make the operation
> truly atomic.  The definition from linux-2.4.x/include/asm-m68k/atomic.h:

> static __inline__ void atomic_inc(volatile atomic_t *v)
> {
> 	__asm__ __volatile__("addql #1,%0" : "=m" (*v): "0" (*v));
> }

> static __inline__ void atomic_dec(volatile atomic_t *v)
> {
> 	__asm__ __volatile__("subql #1,%0" : "=m" (*v): "0" (*v));
> }

> Unfortunately when used they generate the following warning from
> parse_input_contstraint in gcc/stmt.c:

>   if (saw_match && !*allows_reg)
>     warning ("matching constraint does not allow a register");

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));

(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.)

David Carlton
carlton@kealia.com

static inline __attribute__((__always_inline__)) void
atomic_add_long(volatile unsigned long *p, unsigned long v)
{
//     __asm __volatile( "lock ; addl %1,%0" : "+m" (*p) : "ir" (v));
    __asm __volatile( "lock ; addl %2,%0" : "=m" (*p) : "0" (*p), "ir" (v));
}

void increment( unsigned long &x ) {
    atomic_add_long( &x, 1 );
}


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