Subject: Re: advice on some inline assembler code
To: None <port-pc532@netbsd.org>
From: Jon Buller <jonb@metronet.com>
List: port-pc532
Date: 09/27/1998 16:36:06
[ I meant this to go to Matthias, and cc: port-pc532.  I got it to
  prot-pc532 by mistake.  I really need to tune up my mail tools
  one of these days... ]

leo@klondike.dachau.marco.de (Matthias Pfaller) writes:

> In article <199809270100.UAA21442@bullbox.heeia.hi.us>,
> 	jonb@metronet.com (Jon Buller) writes:
> > I have the following code that seems to work with PostgreSQL 6.4
> > 
> >     static __inline__ int
> >     tas(volatile slock_t *lock)
> >     {
> >       register _res;
> >       __asm__("sbitb 0, %0
> >             sprb us, %1
> >             andd 32, %1"
> >            : "=m"(*lock)
> >            : "r"(_res));
> >       return (int) _res;
> >     }
> > 
> > (checked out of their CVS tree a few days ago)  The only problem
> > with it is that I detest the warning gcc spits out about _res
> > probably being uninitialized. 
> 
> That's because you added _res to the list of input operands for your
> assembler pattern. You have to add it to the list of output operands.
> Try the following definition:
> 
>     static __inline__ int
>     tas(volatile slock_t *lock)
>     {
>       register _res;
>       __asm__("sbitb 0,%0; sfs %1" : "=m"(*lock), "r"(_res));
>       return (int) _res;
>     }
> 
> "sfs" (Scondi, save condition as boolean) should store a "1" to _res
> when the flag bit is set due to the "sbitb" instruction.

Thanks again Matthias.  You missed one thing though, "r" needs to
be "=r".  I had tried something similar to that before, and the
error made me look at the VAX code, and that made me modify it to
the top piece of code rather than the bottom.  Is there anyplace
this is documented, so a mere mortal can figure out if they need
colons or commas seperating things, if the things should be "r",
"=r", "=m", "=g", etc.?

Also, I should have looked harder for Scondi, as I really didn't
like the sprb/andd combo.  This is a CISC after all, in fact it's
one of the most CISC of the CISCs.  There HAD to be an exactly
matching single machine instruction for what I wanted. 8-)

Jon Buller


------- End of Forwarded Message