Atomic swap

Portante, Peter peter.portante at hp.com
Thu Aug 7 12:15:53 PDT 2003


> > > 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.
> 
And you should also consider that when the code loops, you want to issue the memory operation as soon as possible, which means performing the mov after the ldq_l.

-Peter


More information about the freebsd-alpha mailing list