This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Call for compiler help/advice: atomic builtins for v3


On Mon, Nov 07, 2005 at 01:35:13AM +0100, Paolo Carlini wrote:
> We have to add to the library
> out-of-line versions of the builtins... (in order to do that, we may end
> up restoring the old inline assembly implementations of CAS, for example)

I don't think you need to restore inline assembly.

> If I understand correctly, this is what we are already doing in the
> *.so, for i386 vs i486+. I would not call that "optimization flag",
> however. Can you clarify?

I'm not sure how you were previously controling what went in here.
By configuration name?  That's certainly one way to do it, and 
probably the most reliable.

Another method is to use -march=i486 on the command line, and from
there use the __i486__ defines already present to determine what
to do.  Note that, at least for x86, -mtune=cpu affects __tune_cpu__,
but not __cpu__.

My thinking would be along the lines of


#if !ARCH_ALWAYS_HAS_SYNC_BUILTINS
_Atomic_word
__exchange_and_add(volatile _Atomic_word* __mem, int __val)
{
#if ARCH_HAS_SYNC_BUILTINS
  return __sync_fetch_and_add(__mem, __val);
#else
  __gthread_mutex_lock (&mutex);
  _Atomic_word ret = *__mem;
  *__mem = ret + __val;
  __gthread_mutex_unlock (&mutex);
  return ret;
#endif
}

void
__atomic_add(volatile _Atomic_word* __mem, int __val)
{
#if ARCH_HAS_SYNC_BUILTINS
  __sync_fetch_and_add(__mem, __val);
#else
  __gthread_mutex_lock (&mutex);
  *__mem += __val;
  __gthread_mutex_unlock (&mutex);
#endif
}
#endif

This definition applies identically to *all* platforms.

For x86, the config file would have

#define ARCH_ALWAYS_HAS_SYNC_BUILTINS 0
#define ARCH_HAS_SYNC_BUILTINS \
  (__i486__ || __i586__ || __i686__ || __k6__ || __athlon__ || \
   __k8__ || __pentium4__ || __nocona__)

We then arrange for the appropriate -march= -mtune= combination
to be set by the configury.  You might want to examine what I'm
doing with this kind of thing for libgomp.


r~


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]