acinclude.m4 (GLIBCXX_ENABLE_ATOMIC_BUILTINS): New.

2006-07-14  Benjamin Kosnik  <bkoz@redhat.com>

        * acinclude.m4 (GLIBCXX_ENABLE_ATOMIC_BUILTINS): New.
        * configure.ac: Use it.
        * configure: Regenerated.	
        * config.h.in: Regenerated.		
        * configure.host: Simplify.
        * include/bits/atomicity.h: Adjust macros.	
        * 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.
	* config/cpu/mips/atomicity.h: Comment MIPS II requirement.

	* scripts/testsuite_flags.in: Make --cxxflags reflect CXXFLAGS.

From-SVN: r115456
This commit is contained in:
Benjamin Kosnik 2006-07-14 22:41:43 +00:00 committed by Benjamin Kosnik
parent 8fce9db014
commit 701a3eeeef
11 changed files with 238 additions and 128 deletions

View File

@ -1,3 +1,21 @@
2006-07-14 Benjamin Kosnik <bkoz@redhat.com>
* acinclude.m4 (GLIBCXX_ENABLE_ATOMIC_BUILTINS): New.
* configure.ac: Use it.
* configure: Regenerated.
* config.h.in: Regenerated.
* configure.host: Simplify.
* include/bits/atomicity.h: Adjust macros.
* 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.
* config/cpu/mips/atomicity.h: Comment MIPS II requirement.
* scripts/testsuite_flags.in: Make --cxxflags reflect CXXFLAGS.
2006-07-14 Paolo Carlini <pcarlini@suse.de>
* include/tr1/random (minstd_rand0, minstd_rand, ranlux3, ranlux4):

View File

@ -1966,6 +1966,69 @@ AC_DEFUN([GLIBCXX_ENABLE_PCH], [
])
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 Note:
dnl libgomp and libgfortran do this with a link test, instead of an asm test.
dnl see: CHECK_SYNC_FETCH_AND_ADD
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;
const atomic_type c3(0);
if (__sync_fetch_and_add(&c1, c2) == c3)
{
// Do something.
}
return 0;
}
EOF
old_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -S"
if AC_TRY_EVAL(ac_compile); then
if grep __sync_fetch_and_add conftest.s >/dev/null 2>&1 ; then
enable_atomic_builtins=no
else
AC_DEFINE(_GLIBCXX_ATOMIC_BUILTINS, 1,
[Define if builtin atomic operations are supported on this host.])
enable_atomic_builtins=yes
atomicity_dir=cpu/generic/atomicity_builtins
fi
fi
CXXFLAGS="$old_CXXFLAGS"
rm -f conftest*
# Now, if still generic, set to mutex.
if test $atomicity_dir = "cpu/generic" ; then
atomicity_dir=cpu/generic/atomicity_mutex
fi
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

View File

@ -655,7 +655,7 @@
/* Version number of package */
#undef VERSION
/* Define if atomic builtins are provided for this platform. */
/* Define if builtin atomic operations are supported on this host. */
#undef _GLIBCXX_ATOMIC_BUILTINS
/* Define to use concept checking code from the boost libraries. */

View File

@ -28,10 +28,13 @@
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
#include <bits/atomicity.h>
#include <bits/c++config.h>
#include <bits/atomic_word.h>
_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
// XXX GLIBCXX_ABI Deprecated
// Should be inlined, and not exported.
_Atomic_word
__attribute__ ((__unused__))
__exchange_and_add(volatile _Atomic_word* __mem, int __val)

View File

@ -1,6 +1,7 @@
// Low-level functions for atomic operations: MIPS version -*- C++ -*-
// Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 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
@ -31,6 +32,7 @@
_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
// NB: MIPS II or above required.
_Atomic_word
__attribute__ ((__unused__))
__exchange_and_add(volatile _Atomic_word* __mem, int __val)

View File

@ -7994,7 +7994,71 @@ _ACEOF
if test $atomicity_dir = cpu/generic ; then
echo "$as_me:$LINENO: checking for atomic builtins" >&5
echo $ECHO_N "checking for atomic builtins... $ECHO_C" >&6
ac_ext=cc
ac_cpp='$CXXCPP $CPPFLAGS'
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
# Fake what AC_TRY_COMPILE does. XXX Look at redoing this new-style.
cat > conftest.$ac_ext << EOF
#line 8011 "configure"
int main()
{
// NB: _Atomic_word not necessarily int.
typedef int atomic_type;
atomic_type c1;
atomic_type c2;
const atomic_type c3(0);
if (__sync_fetch_and_add(&c1, c2) == c3)
{
// Do something.
}
return 0;
}
EOF
old_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -S"
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; then
if grep __sync_fetch_and_add conftest.s >/dev/null 2>&1 ; then
enable_atomic_builtins=no
else
cat >>confdefs.h <<\_ACEOF
#define _GLIBCXX_ATOMIC_BUILTINS 1
_ACEOF
enable_atomic_builtins=yes
atomicity_dir=cpu/generic/atomicity_builtins
fi
fi
CXXFLAGS="$old_CXXFLAGS"
rm -f conftest*
# Now, if still generic, set to mutex.
if test $atomicity_dir = "cpu/generic" ; then
atomicity_dir=cpu/generic/atomicity_mutex
fi
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
echo "$as_me:$LINENO: result: $enable_atomic_builtins" >&5
echo "${ECHO_T}$enable_atomic_builtins" >&6
if test $atomicity_dir = cpu/generic/atomic_mutex ; then
{ echo "$as_me:$LINENO: WARNING: No native atomic operations are provided for this platform." >&5
echo "$as_me: WARNING: No native atomic operations are provided for this platform." >&2;}
if test $target_thread_file = single; then
@ -109919,14 +109983,6 @@ ABI_TWEAKS_SRCDIR=config/${abi_tweaks_dir}
# Atomic builtins can be inlined in bits/atomicity.h.
if test $atomicity_dir = cpu/generic/atomic_builtins ; then
cat >>confdefs.h <<\_ACEOF
#define _GLIBCXX_ATOMIC_BUILTINS 1
_ACEOF
fi
# Determine cross-compile flags and AM_CONDITIONALs.
#AC_SUBST(GLIBCXX_IS_NATIVE)

View File

@ -112,7 +112,8 @@ GLIBCXX_ENABLE_FULLY_DYNAMIC_STRING([no])
# No surprises, no surprises...
GLIBCXX_ENABLE_THREADS
if test $atomicity_dir = cpu/generic ; then
GLIBCXX_ENABLE_ATOMIC_BUILTINS
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 +322,6 @@ AC_SUBST(CPU_DEFINES_SRCDIR)
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)

View File

@ -67,13 +67,16 @@
c_model=c_std
c_compatibility=no
atomic_word_dir=cpu/generic
cpu_defines_dir=cpu/generic
atomicity_dir="cpu/generic"
cpu_defines_dir="cpu/generic"
try_cpu=generic
abi_tweaks_dir="cpu/generic"
# HOST-SPECIFIC OVERRIDES
# Set any CPU-dependent bits.
# Here we override defaults and catch more general cases due to naming
# conventions (e.g., chip_name* to catch all variants).
# Provide a way to funnel exotic flavors and prefixed/postfixed chip
# variants into the established source config/cpu/* sub-directories.
# THIS TABLE IS SORTED. KEEP IT THAT WAY.
case "${host_cpu}" in
alpha*)
@ -89,11 +92,7 @@ case "${host_cpu}" in
try_cpu=hppa
;;
mips*)
# NB: cpu/mips/atomicity.h needs MIPS II or above.
# Of course, there is no sane way to test for this, no ABI macro,
# and no consistent host_cpu name differentiation. Therefore, only
# use it where it is known to be safe, ie it runs linux (see below).
try_cpu=generic
try_cpu=mips
;;
m680[246]0)
try_cpu=m68k
@ -101,31 +100,21 @@ case "${host_cpu}" in
powerpc* | rs6000)
try_cpu=powerpc
;;
s390x)
try_cpu=s390
;;
sparc* | ultrasparc)
try_cpu=sparc
;;
*)
if test -d ${glibcxx_srcdir}/config/cpu/${host_cpu}; then
try_cpu=${host_cpu}
else
try_cpu=generic
fi
;;
esac
# Set specific CPU overrides for atomic_word_dir. Most can just use generic.
# THIS TABLE IS SORTED. KEEP IT THAT WAY.
case "${host_cpu}" in
cris*)
atomic_word_dir=cpu/cris
;;
sparc* | ultrasparc)
atomic_word_dir=cpu/sparc
;;
esac
# Now look for the file(s) usually tied to a CPU model, and make
# default choices for those if they haven't been explicitly set
# already.
cpu_include_dir=cpu/${try_cpu}
# Set specific CPU overrides for cpu_defines_dir. Most can just use generic.
# THIS TABLE IS SORTED. KEEP IT THAT WAY.
@ -135,32 +124,41 @@ case "${host_cpu}" in
;;
esac
# Now look for the file(s) usually tied to a CPU model, and make
# default choices for those if they haven't been explicitly set
# already.
cpu_include_dir=cpu/${try_cpu}
abi_baseline_pair=${try_cpu}-${host_os}
unset try_cpu
# Set specific CPU overrides for atomic_word_dir. Most can just use generic.
# THIS TABLE IS SORTED. KEEP IT THAT WAY.
case "${host_cpu}" in
alpha* | ia64 | powerpc* | rs6000 | s390*)
atomicity_dir="cpu/generic/atomic_builtins"
alpha*)
atomic_word_dir=cpu/alpha
;;
*)
if test -f ${glibcxx_srcdir}/config/${cpu_include_dir}/atomicity.h ; then
atomicity_dir=$cpu_include_dir
else
atomicity_dir="cpu/generic"
fi
cris*)
atomic_word_dir=cpu/cris
;;
ia64)
atomic_word_dir=cpu/ia64
;;
powerpc* | rs6000)
atomic_word_dir=cpu/powerpc
;;
sparc* | ultrasparc)
atomic_word_dir=cpu/sparc
;;
esac
# Set specific CPU overrides for atomicity_dir.
# This can be over-ridden in GLIBCXX_ENABLE_ATOMIC_BUILTINS.
# THIS TABLE IS SORTED. KEEP IT THAT WAY.
if test -f ${glibcxx_srcdir}/config/${cpu_include_dir}/atomicity.h ; then
atomicity_dir=$cpu_include_dir
fi
if test -f ${glibcxx_srcdir}/config/${cpu_include_dir}/cxxabi_tweaks.h ; then
abi_tweaks_dir=$cpu_include_dir
else
abi_tweaks_dir="cpu/generic"
fi
# Set any OS-dependent bits.
# Set the os_include_dir.
# Set c_model, c_compatibility here.
@ -276,39 +274,39 @@ esac
# Set any OS-dependent and CPU-dependent bits.
# THIS TABLE IS SORTED. KEEP IT THAT WAY.
case "${host}" in
alpha*-*-freebsd5*)
abi_baseline_pair="alpha-freebsd5"
*-*-linux*)
case "${host_cpu}" in
i[567]86)
abi_baseline_pair=i486-linux-gnu
;;
powerpc64)
abi_baseline_pair=powerpc64-linux-gnu
;;
s390)
abi_baseline_pair=s390-linux-gnu
;;
s390x)
abi_baseline_pair=s390x-linux-gnu
;;
x86_64)
abi_baseline_pair=x86_64-linux-gnu
;;
*)
if test -d ${glibcxx_srcdir}/config/abi/post/${try_cpu}-linux-gnu; then
abi_baseline_pair=${try_cpu}-linux-gnu
fi
esac
;;
arm*-*-linux*)
abi_baseline_pair="arm-linux-gnu"
;;
i*86-*-freebsd4*)
abi_baseline_pair="i386-freebsd4"
;;
i*86-*-freebsd5*)
abi_baseline_pair="i386-freebsd5"
;;
mips*-*-linux*)
atomicity_dir="cpu/mips"
abi_baseline_pair="mips-linux-gnu"
cpu_include_dir="cpu/mips"
mips*-*-*)
case "${host_os}" in
gnu* | linux* | irix*)
;;
*)
atomicity_dir="cpu/generic"
;;
esac
;;
powerpc*-*-darwin*)
port_specific_symbol_files="\$(srcdir)/../config/os/bsd/darwin/ppc-extra.ver"
;;
powerpc64-*-linux*)
abi_baseline_pair="powerpc64-linux-gnu"
;;
s390-*-linux*)
abi_baseline_pair="s390-linux-gnu"
;;
s390x-*-linux*)
abi_baseline_pair="s390x-linux-gnu"
;;
sparc*-*-freebsd5*)
abi_baseline_pair="sparc-freebsd5"
;;
x86_64-*-linux*)
abi_baseline_pair="x86_64-linux-gnu"
;;
esac

View File

@ -41,6 +41,15 @@
_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
#ifdef _GLIBCXX_ATOMIC_BUILTINS
static inline _Atomic_word
__exchange_and_add(volatile _Atomic_word* __mem, int __val)
{ return __sync_fetch_and_add(__mem, __val); }
static inline void
__atomic_add(volatile _Atomic_word* __mem, int __val)
{ __sync_fetch_and_add(__mem, __val); }
#else
_Atomic_word
__attribute__ ((__unused__))
__exchange_and_add(volatile _Atomic_word* __mem, int __val);
@ -48,34 +57,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
void
__attribute__ ((__unused__))
__atomic_add(volatile _Atomic_word* __mem, int __val);
static inline _Atomic_word
__exchange_and_add_multi(volatile _Atomic_word* __mem, int __val)
{
#ifdef _GLIBCXX_ATOMIC_BUILTINS
return __sync_fetch_and_add(__mem, __val);
#else
return __exchange_and_add(__mem, __val);
#endif
}
static inline void
__atomic_add_multi(volatile _Atomic_word* __mem, int __val)
{
#ifdef _GLIBCXX_ATOMIC_BUILTINS
__sync_fetch_and_add(__mem, __val);
#else
__atomic_add(__mem, __val);
#endif
}
static inline _Atomic_word
__exchange_and_add_single(volatile _Atomic_word* __mem, int __val)
@ -94,16 +76,12 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
__exchange_and_add_dispatch(volatile _Atomic_word* __mem, int __val)
{
#ifdef __GTHREADS
if (__gthread_active_p())
return __exchange_and_add_multi(__mem, __val);
return __exchange_and_add(__mem, __val);
else
return __exchange_and_add_single(__mem, __val);
#else
return __exchange_and_add_single(__mem, __val);
#endif
}
@ -112,23 +90,19 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
__atomic_add_dispatch(volatile _Atomic_word* __mem, int __val)
{
#ifdef __GTHREADS
if (__gthread_active_p())
__atomic_add_multi(__mem, __val);
__atomic_add(__mem, __val);
else
__atomic_add_single(__mem, __val);
#else
__atomic_add_single(__mem, __val);
#endif
}
_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

View File

@ -50,7 +50,7 @@ case ${query} in
--cxxflags)
CXXFLAGS_save="-g -O2 -D_GLIBCXX_ASSERT"
CXXFLAGS_config='@SECTION_FLAGS@ -fmessage-length=0
@EXTRA_CXX_FLAGS@ '
@CXXFLAGS@ @EXTRA_CXX_FLAGS@ '
echo ${CXXFLAGS_save} ${CXXFLAGS_config}
;;
--cxxpchflags)