Atomic swap

Daniel Eischen eischen at vigrid.com
Thu Aug 7 12:22:41 PDT 2003


On Thu, 7 Aug 2003, Portante, Peter wrote:

> Dan,
> 
> > ----------
> > From: 	Daniel Eischen
> > Reply To: 	deischen at freebsd.org
> > Sent: 	Thursday, August 7, 2003 3:05 PM
> > To: 	Marcel Moolenaar
> > Cc: 	Portante, Peter; alpha at freebsd.org; deischen at freebsd.org
> > Subject: 	Re: Atomic swap
> > 
> > On Thu, 7 Aug 2003, Marcel Moolenaar wrote:
> > 
> > > static __inline void
> > > atomic_swap_long(volatile long *dst, long val, long *res)
> > > {
> > > 	__asm (	"1: ldq_l   t0,%0\n"
> > > 		"   mov     %1,t1\n"
> > 
> > If I swap the first 2 instructions:
> > 
> > 	__asm ( "1: mov     %1,t1\n"
> > 		    ldq_l   t0,%0\n"
> > 
> > that eliminates 1 instruction from between the locked
> > instructions.  Is there anything wrong with doing that?
> > 
> Actually, the processor has a chance to do something while waiting for
> memory, so it does not hurt to have the mov inside the ldq_l/stq_c pair.

I'm just thinking that it could narrow the window in which
you can get a contention, but if the window is the same
regardless of the order of those 2 instructions, then
that's OK.

-- 
Dan Eischen



More information about the freebsd-alpha mailing list