[cpp-threads] modes, pass 2

Alexander Terekhov alexander.terekhov at gmail.com
Wed May 11 19:58:39 BST 2005


On 5/11/05, Doug Lea <dl at cs.oswego.edu> wrote:
[...]
> 1. There are only a few modes on atomics that are worth exposing
>    1. load, suppressing any speculative forward loads
>    2. store, suppressing reorderings wrt preceeding stores
>    3. store, ensuring that read-after-write works

Well, apart from dd/cc stuff, full modes atomic_load() and 
atomic_store() in pseudocode for Power is this:

template<class T, class M> T atomic_load( M msync, T * addr )
/* "#pragma" */compiler_reordering_constraint_across_this_function( M )
{
   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;
}

template<class T, class M> T atomic_store( M msync, T * addr, T val )
/* "#pragma" */compiler_reordering_constraint_across_this_function( M )
{
   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
   }
}

See also

http://www.decadentplace.org.uk/pipermail/cpp-threads_decadentplace.org.uk/2005-May/000447.html
http://www.decadentplace.org.uk/pipermail/cpp-threads_decadentplace.org.uk/2005-May/000451.html

So what's the problem? (If it can be done for Power and Sparc RMO,
then doing it for anything else is just a peanut, oder? ;-) )

regards,
alexander.




More information about the cpp-threads mailing list