Subject: Re: VAX atomic test-and-set?
To: None <port-vax@NetBSD.ORG>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: port-vax
Date: 02/04/1998 17:01:35
> I needed an atomic test-and-set for the VAX, and I believe I've got
> it right with the following -- [...]
> static int tas(int *lock) {
> asm("movl 4(ap), r0");
> asm("bbssi $0, (r0), 1f");
> asm("clrl r0");
> asm("1: ret");
> }
Your assumptions about bbssi are *supposed* to be valid. I am not
experienced enough with any model of VAX to know whether they actually
are...but if not, I'm sure it would be considered a bug in the
implementation. Indeed, the operation is *supposed* to be interlocked
even against other CPUs in a multiprocessor machine.
> While I'm asking, how can I make this secure against GCC
> optimization? The damn thing inlines my assembly code at
> optimization levels above -O2, which breaks this stuff completely.
You might try using a single asm:
asm("movl 4(ap),r0; bbssi $0,(r0),1f; clrl r0; 1:ret");
You really _ought_ to use gcc's syntax for referring to variables
instead of assuming 4(ap), which I think is probably the real source of
the breakage you're seeing when the code gets inlined. Here's my guess
at the sort of thing you'd have to write; someone who actually knows
the extended-asm syntax should check it:
static int tas(int *lock) {
int rv;
asm( "movl %1,r0; bbssi $0,(r0),1f; clrl r0; 1:movl r0,%0"
: "=g" (rv)
: "g" (lock)
: "r0" );
return(rv);
}
der Mouse
mouse@rodents.montreal.qc.ca
7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B