Atomic COMPARE_AND_EXCHANGE (Was: Re: [kaffe] NetBSD/68k asm error!!)

Dalibor Topic robilad at kaffe.org
Fri Dec 5 15:28:01 PST 2003


Riccardo wrote:
> I never got an error like this in my life :
> 
>  gcc -DHAVE_CONFIG_H -I. -I../../../kaffe/kaffe/kaffevm -I../../config -
> I../../include/kaffe -I../../../kaffe/kaffe/kaffevm/systems/unix-
> jthreads -I../../kaffe/kaffevm/jit3 -I../../../kaffe/kaffe/kaffevm/jit3 -
> I../../../kaffe/libltdl -DTRANSLATOR -DJIT3 -I../../../kaffe/kaffe/jvmpi -
> I../../../kaffe/kaffe/xprof -I../../include -DKVER=\"1.1.x-cvs\" -I/home/
> multix/kaffe-cvs/netbsd-68k/../kaffe/kaffe/kaffevm -I/home/multix/kaffe-
> cvs/netbsd-68k/../kaffe/kaffe/kaffevm/jit3 -I/home/multix/kaffe-cvs/
> netbsd-68k/../kaffe/kaffe/kaffevm/systems/unix-jthreads -I../../../kaffe/
> config -I../../../kaffe/include -DKAFFE_VMDEBUG -g -O2 -Wall -Wstrict-
> prototypes -fno-omit-frame-pointer -c ../../../kaffe/kaffe/kaffevm/locks.
> c -Wp,-MD,.deps/locks.TPlo  -fPIC -DPIC -o .libs/locks.o
> /var/tmp/ccTh5fPf.s: Assembler messages:
> /var/tmp/ccTh5fPf.s:2248: Error: operands mismatch -- statement `casl %
> a0,%d3,(%a2)' ignored
> gmake[3]: *** [locks.lo] Error 1

Kiyo Inaba looked at that one, it seems to be a bug in kaffe's m68k 
assembler sources, namely the COMPARE_AND_EXCHANGE macro. See 
http://gcc.gnu.org/ml/gcc-bugs/2003-04/msg00753.html

There is some code at 
http://www.uclibc.org/lists/uclibc/2002-August/004205.html that is about 
writing a compare_and_swap macro for a coldfire CPU for uclibc that 
might be interesting to take a look at. Tony had some ideas how to deal 
with it here: http://www.kaffe.org/pipermail/kaffe/2003-February/041462.html

I have a couple of ideas (though I don;t speak m68k assembler, so they 
may be bogus, you've been warned):

1. My guess is that the constraint for the first argument of casl is 
wrong, it should be a data register. Does changing "=&r" (tmp) into 
"=&d" (tmp) in line 181 of kaffe/config/m68k/common.h work?

2. Does reverting m68k to plain C COMPARE_AND_EXCHNAGE as proposed by me 
here: http://www.kaffe.org/pipermail/kaffe/2003-February/041464.html  work?

For the long term, of course, atomic compare and exchange on different 
CPUs would be a good thing to delegate to a library. I'm not aware of 
any such library, but there was some talk on the linux kernel mailing 
list about such beasts here:
http://www.mail-archive.com/linux-audio-dev@music.columbia.edu/msg10303.html

The solution I have in mind is to use the code from glibc (in 
sysdeps/cpu-type/atomicity.h), like SableVM does.

glibc 2.3.2 has this for m68k ('20 and above due to casl, which is what 
kaffe is using, too):

static inline int
__attribute__ ((unused))
compare_and_swap (volatile long int *p, long int oldval, long int newval)
{
   char ret;
   long int readval;

   __asm__ __volatile__ ("cas%.l %2,%3,%1; seq %0"
                         : "=dm" (ret), "=m" (*p), "=d" (readval)
                         : "d" (newval), "m" (*p), "2" (oldval));
   return ret;
}



cheers,
dalibor topic






More information about the kaffe mailing list