[cpp-threads] modes, pass 2

Alexander Terekhov alexander.terekhov at gmail.com
Mon May 9 22:35:29 BST 2005


On 5/9/05, Alexander Terekhov <alexander.terekhov at gmail.com> wrote:
> On 5/9/05, Peter Dimov <pdimov at mmltd.net> wrote:
> > Alexander Terekhov wrote:
> > > I think that the trick can be used for your get_acquire().
> >
> > Yep. In "compilable pseudocode":
> >
> > template<class T, class M> T atomic_load( M msync, T * addr )
> > {
> >    if( msync & msync_ssb )
> >    {
> >        _sync();
> >    }
> >    else if( msync & msync_slb )
> >    {
> >        _lwsync();
> >    }
> >
> >    T r = _load( addr );
> >
> >    if( msync & msync_acq )
> >    {
> >        _inject_conditional_branch();
> >    }
> >
> >    if( msync & msync_hlb )
> >    {
> >        _isync();
> >    }
> >
> >    return r;
> > }
> 
> Yup. With compile time ifs, "_inject_conditional_branch()" meaning
> r->CR0->branch-never-taken hack, msync_acq == msync_hsb | msync_hlb,
> and Doug's "lightest barrier" stuff implied.

template<class T, class M> T atomic_store( M msync, T * addr, T val )
{
   if( msync & msync_slb )
   {
       _lwsync();
   }
   else if( msync & msync_ssb )
   {
       _eieio(); // probably cheaper than lwsync
   }

   _store( addr, val );

   if( msync & msync_hlb )
   {
       _sync();
   }
   else if( msync & msync_hsb )
   {
       _eieio(); // probably cheaper than sync
   }

   return val;
}

Well, and I suppose that for "msync & msync_acq != 0" (sorta unusual 
for atomic_store(), but still) it can be cheaper to replace _store() 
+ sync/eieio with LR-SC loop and trailing if( msync & msync_hlb ) { 
_isync(); }.  

regards,
alexander.




More information about the cpp-threads mailing list