2006-07-06 Benjamin Kosnik * config/cpu/generic/atomicity.h: Move... * config/cpu/generic/atomicity_mutex: New. * config/cpu/generic/atomicity_mutex/atomicity.h: ...here. * config/cpu/generic/atomic_builtins: Rename... * config/cpu/generic/atomicity_builtins: ...to this. * config/cpu/generic/atomicity_builtins/atomicity.h: Moved. * configure.host (atomicity_dir): Simplify. * acinclude.m4 (GLIBCXX_HAVE_ATOMIC_BUILTINS): New. * configure.ac: Use it. Remove _GLIBCXX_ATOMIC_BUILTINS. * include/bits/atomicity.h: Adjust macros. Index: include/bits/atomicity.h =================================================================== --- include/bits/atomicity.h (revision 115226) +++ include/bits/atomicity.h (working copy) @@ -52,7 +52,7 @@ static inline _Atomic_word __exchange_and_add_multi(volatile _Atomic_word* __mem, int __val) { -#ifdef _GLIBCXX_ATOMIC_BUILTINS +#ifdef _GLIBCXX_HAVE_ATOMIC_BUILTINS return __sync_fetch_and_add(__mem, __val); @@ -66,7 +66,7 @@ static inline void __atomic_add_multi(volatile _Atomic_word* __mem, int __val) { -#ifdef _GLIBCXX_ATOMIC_BUILTINS +#ifdef _GLIBCXX_HAVE_ATOMIC_BUILTINS __sync_fetch_and_add(__mem, __val); @@ -127,8 +127,8 @@ _GLIBCXX_END_NAMESPACE -/* Even if the CPU doesn't need a memory barrier, we need to ensure that - the compiler doesn't reorder memory accesses across the barriers. */ +// Even if the CPU doesn't need a memory barrier, we need to ensure that +// the compiler doesn't reorder memory accesses across the barriers. #ifndef _GLIBCXX_READ_MEM_BARRIER #define _GLIBCXX_READ_MEM_BARRIER __asm __volatile ("":::"memory") #endif Index: configure.host =================================================================== --- configure.host (revision 115226) +++ configure.host (working copy) @@ -142,18 +142,12 @@ abi_baseline_pair=${try_cpu}-${host_os} unset try_cpu -case "${host_cpu}" in - alpha* | ia64 | powerpc* | rs6000 | s390*) - atomicity_dir="cpu/generic/atomic_builtins" - ;; - *) - if test -f ${glibcxx_srcdir}/config/${cpu_include_dir}/atomicity.h ; then - atomicity_dir=$cpu_include_dir - else - atomicity_dir="cpu/generic" - fi - ;; -esac +# First check for atomics, check for compiler builtins later in configure. +if test -f ${glibcxx_srcdir}/config/${cpu_include_dir}/atomicity.h ; then + atomicity_dir=$cpu_include_dir +else + atomicity_dir="cpu/generic" +fi if test -f ${glibcxx_srcdir}/config/${cpu_include_dir}/cxxabi_tweaks.h ; then abi_tweaks_dir=$cpu_include_dir Index: configure.ac =================================================================== --- configure.ac (revision 115226) +++ configure.ac (working copy) @@ -113,6 +113,9 @@ # No surprises, no surprises... GLIBCXX_ENABLE_THREADS if test $atomicity_dir = cpu/generic ; then + GLIBCXX_ENABLE_ATOMIC_BUILTINS +fi +if test $atomicity_dir = cpu/generic/atomic_mutex ; then AC_MSG_WARN([No native atomic operations are provided for this platform.]) if test $target_thread_file = single; then AC_MSG_WARN([They cannot be faked when thread support is disabled.]) @@ -321,11 +324,6 @@ AC_SUBST(ABI_TWEAKS_SRCDIR) AC_SUBST(OS_INC_SRCDIR) -# Atomic builtins can be inlined in bits/atomicity.h. -if test $atomicity_dir = cpu/generic/atomic_builtins ; then - AC_DEFINE([_GLIBCXX_ATOMIC_BUILTINS], 1, - [Define if atomic builtins are provided for this platform.]) -fi # Determine cross-compile flags and AM_CONDITIONALs. #AC_SUBST(GLIBCXX_IS_NATIVE) Index: config/cpu/generic/atomic_builtins/atomicity.h =================================================================== --- config/cpu/generic/atomic_builtins/atomicity.h (revision 115226) +++ config/cpu/generic/atomic_builtins/atomicity.h (working copy) @@ -1,45 +0,0 @@ -// Low-level functions for atomic operations: version for CPUs providing -// atomic builtins -*- C++ -*- - -// Copyright (C) 2006 Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -// USA. - -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -#include - -_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) - - _Atomic_word - __attribute__ ((__unused__)) - __exchange_and_add(volatile _Atomic_word* __mem, int __val) - { return __sync_fetch_and_add(__mem, __val); } - - void - __attribute__ ((__unused__)) - __atomic_add(volatile _Atomic_word* __mem, int __val) - { __sync_fetch_and_add(__mem, __val); } - -_GLIBCXX_END_NAMESPACE Index: config/cpu/generic/atomicity.h =================================================================== --- config/cpu/generic/atomicity.h (revision 115226) +++ config/cpu/generic/atomicity.h (working copy) @@ -1,58 +0,0 @@ -// Low-level functions for atomic operations: Generic version -*- C++ -*- - -// Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005 -// Free Software Foundation, Inc. -// -// This file is part of the GNU ISO C++ Library. This library is free -// software; you can redistribute it and/or modify it under the -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -// USA. - -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. - -#include -#include - -namespace __gnu_internal -{ - __glibcxx_mutex_define_initialized(atomic_mutex); -} // namespace __gnu_internal - -_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) - - _Atomic_word - __attribute__ ((__unused__)) - __exchange_and_add(volatile _Atomic_word* __mem, int __val) - { - __glibcxx_mutex_lock(__gnu_internal::atomic_mutex); - _Atomic_word __result; - __result = *__mem; - *__mem += __val; - __glibcxx_mutex_unlock(__gnu_internal::atomic_mutex); - return __result; - } - - void - __attribute__ ((__unused__)) - __atomic_add(volatile _Atomic_word* __mem, int __val) - { __exchange_and_add(__mem, __val); } - -_GLIBCXX_END_NAMESPACE Index: acinclude.m4 =================================================================== --- acinclude.m4 (revision 115226) +++ acinclude.m4 (working copy) @@ -1967,6 +1967,58 @@ dnl +dnl Check for atomic builtins. +dnl See: +dnl http://gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html#Atomic-Builtins +dnl +dnl This checks to see if the host supports the compiler-generated +dnl builtins for atomic operations. Note, this is intended to be an +dnl all-or-nothing switch, so all the atomic operations that are used +dnl should be checked. +dnl +dnl Defines: +dnl _GLIBCXX_ATOMIC_BUILTINS if the compiler on this target supports atomics. +dnl +AC_DEFUN([GLIBCXX_ENABLE_ATOMIC_BUILTINS], [ + AC_MSG_CHECKING([for atomic builtins]) + AC_LANG_SAVE + AC_LANG_CPLUSPLUS + + # Fake what AC_TRY_COMPILE does. XXX Look at redoing this new-style. + cat > conftest.$ac_ext << EOF +[#]line __oline__ "configure" +int main() +{ + // NB: _Atomic_word not necessarily int. + typedef int atomic_type; + atomic_type c1; + atomic_type c2; + __sync_bool_compare_and_swap(&c1, c2, c2 + 1); + return 0; +} +EOF + old_CXXFLAGS="$CXXFLAGS" + CXXFLAGS=-S + if AC_TRY_EVAL(ac_compile); then + if grep __sync_bool_compare_and_swap conftest.s >/dev/null 2>&1 ; then + enable_atomic_builtins=no + atomicity_dir = cpu/generic/atomic_mutex + else + AC_DEFINE(_GLIBCXX_HAVE_ATOMIC_BUILTINS, 1, + [Define if builtin atomic operations are supported on this host.]) + enable_atomic_builtins=yes + atomicity_dir = cpu/generic/atomic_builtins + fi + fi + CXXFLAGS="$old_CXXFLAGS" + rm -f conftest* + + AC_LANG_RESTORE + AC_MSG_RESULT($enable_atomic_builtins) +]) + + +dnl dnl Check for exception handling support. If an explicit enable/disable dnl sjlj exceptions is given, we don't have to detect. Otherwise the dnl target may or may not support call frame exceptions.