Re: [PATCH] Re: [v3] updated atomic configury

2011-11-30 Thread Benjamin Kosnik

Thanks Andrew. Here's the updated patch, as checked in. This removes
one level of cruft WRT atomic configure-ness (leaving us with the most
primordial...). 

tested x86/linux
tested x86/linux x arm-eabi
tested x86/linux x cris-elf

-benjamin

2011-11-30  Benjamin Kosnik  b...@redhat.com

* acinclude.m4 (GLIBCXX_ENABLE_ATOMIC_BUILTINS): Remove
size-specific macros. _GLIBCXX_ATOMIC_BUILTINS_1,
_GLIBCXX_ATOMIC_BUILTINS_2, _GLIBCXX_ATOMIC_BUILTINS_4,
_GLIBCXX_ATOMIC_BUILTINS_8. Use _GLIBCXX_ATOMIC_BUILTINS to
indicate use of C++11 atomic builtins.
* config.h.in: Regenerate.
* configure: Regenerate.
* include/Makefile.am (bits_sup_headers): Add atomic_lockfree_defines.h.
* include/Makefile.in: Regenerate.
* libsupc++/Makefile.am: Compile C++11 support with -std=gnu++0x.
* libsupc++/Makefile.in: Regenerate.

* include/bits/atomic_base.h: Move lock-free property macros...
* libsupc++/atomic_lockfree_defines.h: ...here.
* include/std/future: Use C++11 macros.
* libsupc++/eh_ptr.cc: Same.
* libsupc++/eh_throw.cc: Same.
* libsupc++/exception: Same.
* libsupc++/exception_ptr.h: Same.
* libsupc++/guard.cc: Same.
* libsupc++/nested_exception.cc: Same.
* libsupc++/nested_exception.h: Same.
* src/future.cc: Same.

* include/ext/atomicity.h: Use _GLIBCXX_ATOMIC_BUILTINS.

* doc/doxygen/user.cfg.in
* doc/xml/manual/concurrency_extensions.xml

* testsuite/18_support/exception_ptr/lifespan.cc
* testsuite/lib/libstdc++.exp

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index fee5c6f..9d08178 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -2683,12 +2683,6 @@ dnl
 dnl Note:
 dnl libgomp and libgfortran use a link test, see CHECK_SYNC_FETCH_AND_ADD.
 dnl
-dnl Defines:
-dnl  _GLIBCXX_ATOMIC_BUILTINS_1
-dnl  _GLIBCXX_ATOMIC_BUILTINS_2
-dnl  _GLIBCXX_ATOMIC_BUILTINS_4
-dnl  _GLIBCXX_ATOMIC_BUILTINS_8
-dnl
 AC_DEFUN([GLIBCXX_ENABLE_ATOMIC_BUILTINS], [
   AC_LANG_SAVE
   AC_LANG_CPLUSPLUS
@@ -2729,10 +2723,6 @@ AC_DEFUN([GLIBCXX_ENABLE_ATOMIC_BUILTINS], [
   [glibcxx_cv_atomic_bool=yes],
   [glibcxx_cv_atomic_bool=no])
   ])
-  if test $glibcxx_cv_atomic_bool = yes; then
-AC_DEFINE(_GLIBCXX_ATOMIC_BUILTINS_1, 1,
-  [Define if builtin atomic operations for bool are supported on this host.])
-  fi
   AC_MSG_RESULT($glibcxx_cv_atomic_bool)
 
   AC_MSG_CHECKING([for atomic builtins for short])
@@ -2751,10 +2741,6 @@ AC_DEFUN([GLIBCXX_ENABLE_ATOMIC_BUILTINS], [
   [glibcxx_cv_atomic_short=yes],
   [glibcxx_cv_atomic_short=no])
   ])
-  if test $glibcxx_cv_atomic_short = yes; then
-AC_DEFINE(_GLIBCXX_ATOMIC_BUILTINS_2, 1,
-  [Define if builtin atomic operations for short are supported on this host.])
-  fi
   AC_MSG_RESULT($glibcxx_cv_atomic_short)
 
   AC_MSG_CHECKING([for atomic builtins for int])
@@ -2773,10 +2759,6 @@ AC_DEFUN([GLIBCXX_ENABLE_ATOMIC_BUILTINS], [
   [glibcxx_cv_atomic_int=yes],
   [glibcxx_cv_atomic_int=no])
   ])
-  if test $glibcxx_cv_atomic_int = yes; then
-AC_DEFINE(_GLIBCXX_ATOMIC_BUILTINS_4, 1,
-  [Define if builtin atomic operations for int are supported on this host.])
-  fi
   AC_MSG_RESULT($glibcxx_cv_atomic_int)
 
   AC_MSG_CHECKING([for atomic builtins for long long])
@@ -2795,10 +2777,6 @@ AC_DEFUN([GLIBCXX_ENABLE_ATOMIC_BUILTINS], [
   [glibcxx_cv_atomic_long_long=yes],
   [glibcxx_cv_atomic_long_long=no])
   ])
-  if test $glibcxx_cv_atomic_long_long = yes; then
-AC_DEFINE(_GLIBCXX_ATOMIC_BUILTINS_8, 1,
-  [Define if builtin atomic operations for long long are supported on this host.])
-  fi
   AC_MSG_RESULT($glibcxx_cv_atomic_long_long)
 
   else
@@ -2832,8 +2810,6 @@ EOF
   if grep __sync_ conftest.s /dev/null 21 ; then
 	glibcxx_cv_atomic_bool=no
   else
-  AC_DEFINE(_GLIBCXX_ATOMIC_BUILTINS_1, 1,
-  [Define if builtin atomic operations for bool are supported on this host.])
 	glibcxx_cv_atomic_bool=yes
   fi
 fi
@@ -2862,8 +2838,6 @@ EOF
   if grep __sync_ conftest.s /dev/null 21 ; then
 	glibcxx_cv_atomic_short=no
   else
-  AC_DEFINE(_GLIBCXX_ATOMIC_BUILTINS_2, 1,
-  [Define if builtin atomic operations for short are supported on this host.])
 	glibcxx_cv_atomic_short=yes
   fi
 fi
@@ -2893,8 +2867,6 @@ EOF
   if grep __sync_ conftest.s /dev/null 21 ; then
 	glibcxx_cv_atomic_int=no
   else
-  AC_DEFINE(_GLIBCXX_ATOMIC_BUILTINS_4, 1,
-	[Define if builtin atomic operations for int are supported on this host.])
 	glibcxx_cv_atomic_int=yes
   fi
 fi
@@ -2923,8 +2895,6 @@ EOF
   if grep __sync_ conftest.s /dev/null 21 ; then
 	glibcxx_cv_atomic_long_long=no
   else
-  AC_DEFINE(_GLIBCXX_ATOMIC_BUILTINS_8, 1,
-  [Define if builtin atomic operations for long long are supported on this host.])
 	

[PATCH] Re: [v3] updated atomic configury

2011-11-28 Thread Andrew MacLeod

On 11/22/2011 03:48 PM, Joseph S. Myers wrote:

On Tue, 22 Nov 2011, Andrew MacLeod wrote:



It certainly does have those types, as typedefs defined inuchar.h   for
the same types as uint_least16_t and uint_least32_t.  Andstdatomic.h   is
also required to define ATOMIC_CHAR16_T_LOCK_FREE and
ATOMIC_CHAR32_T_LOCK_FREE.

but there isn't a stdatomic.h until we support C1x right? didnt we bail on

It still seems better to predefine the macros for those types, using
char16_type_node and char32_type_node, using them initially for C++ and
then later for C as well.

OK, here's a reworked patch.  This bootstraps but there is a 
regression... one set of PCH tests fail in a very odd way. I've 
investigated it and it turns out that for some reason,  ptr_type_node 
doesn't always have it size set if code isn't being generated (all the 
other nodes do)... in particular I can reproduce it on a small test case 
on my x86-64 machine where size is 8 when generating code, and 0 if -E 
is used to output pre-processed source.  I'm looking into that today.


Question, the purpose of the testcase in the patch  macros.c...  is it 
to simply test for standard compliance, or to test both compliance PLUS 
what we expect?  I made the change assuming the latter.  We will always 
generate a 1 or a 2 for the macros, and we also want the macros to now 
be compile time satisfied so they can be used in #if statements like 
bkoz was trying to do.


Andrew





c-family
* c-cpp-builtin.c (cpp_atomic_builtins):New.  Emit all atomic
predefines in one place.  Add LOCK_FREE predefines.
(c_cpp_builtins): Move Legacy HAVE_SYNC predefines to
new func.

libstdc++-v3
* include/bits/atomic_base.h (ATOMIC_*_LOCK_FREE): Use new cpp
predefined macros.
* testsuite/29_atomics/headers/atomic/macros.cc: Add BOOL and POINTER
macro checks.  Check for expected compile time values.

Index: gcc/c-family/c-cppbuiltin.c
===
*** gcc/c-family/c-cppbuiltin.c (revision 181698)
--- gcc/c-family/c-cppbuiltin.c (working copy)
*** c_cpp_builtins_optimize_pragma (cpp_read
*** 568,573 
--- 568,677 
  }
  
  
+ /* This function will emit cpp macros to indicate the presence of various lock
+free atomic operations.  */
+
+ static void
+ cpp_atomic_builtins (cpp_reader *pfile)
+ {
+   /* Set a flag for each size of object that compare and swap exists for up to
+  a 16 byte object.  */
+ #define SWAP_LIMIT  17
+   bool have_swap[SWAP_LIMIT];
+ 
+   /* Clear the map of sizes compare_and swap exists for.  */
+   memset (have_swap, 0, sizeof (have_swap));
+ 
+   /* Tell source code if the compiler makes sync_compare_and_swap
+  builtins available.  */
+ #ifndef HAVE_sync_compare_and_swapqi
+ #define HAVE_sync_compare_and_swapqi 0
+ #endif
+ #ifndef HAVE_atomic_compare_and_swapqi
+ #define HAVE_atomic_compare_and_swapqi 0
+ #endif
+ 
+   if (HAVE_sync_compare_and_swapqi || HAVE_atomic_compare_and_swapqi)
+ {
+   cpp_define (pfile, __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1);
+   have_swap[1] = true;
+ }
+ 
+ #ifndef HAVE_sync_compare_and_swaphi
+ #define HAVE_sync_compare_and_swaphi 0
+ #endif
+ #ifndef HAVE_atomic_compare_and_swaphi
+ #define HAVE_atomic_compare_and_swaphi 0
+ #endif
+   if (HAVE_sync_compare_and_swaphi || HAVE_atomic_compare_and_swaphi)
+ {
+   cpp_define (pfile, __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2);
+   have_swap[2] = true;
+ }
+ 
+ #ifndef HAVE_sync_compare_and_swapsi
+ #define HAVE_sync_compare_and_swapsi 0
+ #endif
+ #ifndef HAVE_atomic_compare_and_swapsi
+ #define HAVE_atomic_compare_and_swapsi 0
+ #endif
+   if (HAVE_sync_compare_and_swapsi || HAVE_atomic_compare_and_swapsi)
+ {
+   cpp_define (pfile, __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4);
+   have_swap[4] = true;
+ }
+ 
+ #ifndef HAVE_sync_compare_and_swapdi
+ #define HAVE_sync_compare_and_swapdi 0
+ #endif
+ #ifndef HAVE_atomic_compare_and_swapdi
+ #define HAVE_atomic_compare_and_swapdi 0
+ #endif
+   if (HAVE_sync_compare_and_swapdi || HAVE_atomic_compare_and_swapdi)
+ {
+   cpp_define (pfile, __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8);
+   have_swap[8] = true;
+ }
+ 
+ #ifndef HAVE_sync_compare_and_swapti
+ #define HAVE_sync_compare_and_swapti 0
+ #endif
+ #ifndef HAVE_atomic_compare_and_swapti
+ #define HAVE_atomic_compare_and_swapti 0
+ #endif
+   if (HAVE_sync_compare_and_swapti || HAVE_atomic_compare_and_swapti)
+ {
+   cpp_define (pfile, __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16);
+   have_swap[16] = true;
+ }
+ 
+   /* Tell the source code about various types.  These map to the C++11 and C1x
+  macros where 2 indicates lock-free always, and 1 indicates sometimes
+  lock free.  */
+ #define SIZEOF_NODE(T) (tree_low_cst (TYPE_SIZE_UNIT (T), 1))
+ #define SWAP_INDEX(T) ((SIZEOF_NODE (T)  SWAP_LIMIT) ? SIZEOF_NODE (T) : 0)
+   builtin_define_with_int_value 

Re: [PATCH] Re: [v3] updated atomic configury

2011-11-28 Thread Joseph S. Myers
On Mon, 28 Nov 2011, Andrew MacLeod wrote:

 OK, here's a reworked patch.  This bootstraps but there is a regression... one
 set of PCH tests fail in a very odd way. I've investigated it and it turns out
 that for some reason,  ptr_type_node doesn't always have it size set if code
 isn't being generated (all the other nodes do)... in particular I can
 reproduce it on a small test case on my x86-64 machine where size is 8 when
 generating code, and 0 if -E is used to output pre-processed source.  I'm
 looking into that today.

That would be why cppbuiltin.c, defining __SIZEOF_POINTER__, needs to use 
the POINTER_SIZE macro instead of directly using ptr_type_node.  You may 
need to do something similar.

  /* ptr_type_node can't be used here since ptr_mode is only set when
 toplev calls backend_init which is not done with -E switch.  */
  cpp_define_formatted (pfile, __SIZEOF_POINTER__=%d,
POINTER_SIZE / BITS_PER_UNIT);

 Question, the purpose of the testcase in the patch  macros.c...  is it to
 simply test for standard compliance, or to test both compliance PLUS what we
 expect?  I made the change assuming the latter.  We will always generate a 1
 or a 2 for the macros, and we also want the macros to now be compile time
 satisfied so they can be used in #if statements like bkoz was trying to do.

Yes, test that the macros do what we expect.

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: [PATCH] Re: [v3] updated atomic configury

2011-11-28 Thread Andrew MacLeod

On 11/28/2011 11:42 AM, Joseph S. Myers wrote:

On Mon, 28 Nov 2011, Andrew MacLeod wrote:

That would be why cppbuiltin.c, defining __SIZEOF_POINTER__, needs to use
the POINTER_SIZE macro instead of directly using ptr_type_node.  You may
need to do something similar.

   /* ptr_type_node can't be used here since ptr_mode is only set when
  toplev calls backend_init which is not done with -E switch.  */
   cpp_define_formatted (pfile, __SIZEOF_POINTER__=%d,
 POINTER_SIZE / BITS_PER_UNIT);

How bizarre...  thanks you saved me some hair pulling I'm sure :-)  That 
does work, here's a patch which does that..
bootstraps on x86_64-unknown-linux-gnu and has no new regressions.  OK 
for mainline?


Andrew

c-family
* c-cpp-builtin.c (cpp_atomic_builtins):New.  Emit all atomic
predefines in one place.  Add LOCK_FREE predefines.
(c_cpp_builtins): Move Legacy HAVE_SYNC predefines to
new func.

libstdc++-v3
* include/bits/atomic_base.h (ATOMIC_*_LOCK_FREE): Use new cpp
predefined macros.
* testsuite/29_atomics/headers/atomic/macros.cc: Add BOOL and POINTER
macro checks.  Check for expected compile time values.

Index: gcc/c-family/c-cppbuiltin.c
===
*** gcc/c-family/c-cppbuiltin.c (revision 181698)
--- gcc/c-family/c-cppbuiltin.c (working copy)
*** c_cpp_builtins_optimize_pragma (cpp_read
*** 568,573 
--- 568,684 
  }
  
  
+ /* This function will emit cpp macros to indicate the presence of various lock
+free atomic operations.  */
+
+ static void
+ cpp_atomic_builtins (cpp_reader *pfile)
+ {
+   /* Set a flag for each size of object that compare and swap exists for up to
+  a 16 byte object.  */
+ #define SWAP_LIMIT  17
+   bool have_swap[SWAP_LIMIT];
+   unsigned int psize;
+ 
+   /* Clear the map of sizes compare_and swap exists for.  */
+   memset (have_swap, 0, sizeof (have_swap));
+ 
+   /* Tell source code if the compiler makes sync_compare_and_swap
+  builtins available.  */
+ #ifndef HAVE_sync_compare_and_swapqi
+ #define HAVE_sync_compare_and_swapqi 0
+ #endif
+ #ifndef HAVE_atomic_compare_and_swapqi
+ #define HAVE_atomic_compare_and_swapqi 0
+ #endif
+ 
+   if (HAVE_sync_compare_and_swapqi || HAVE_atomic_compare_and_swapqi)
+ {
+   cpp_define (pfile, __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1);
+   have_swap[1] = true;
+ }
+ 
+ #ifndef HAVE_sync_compare_and_swaphi
+ #define HAVE_sync_compare_and_swaphi 0
+ #endif
+ #ifndef HAVE_atomic_compare_and_swaphi
+ #define HAVE_atomic_compare_and_swaphi 0
+ #endif
+   if (HAVE_sync_compare_and_swaphi || HAVE_atomic_compare_and_swaphi)
+ {
+   cpp_define (pfile, __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2);
+   have_swap[2] = true;
+ }
+ 
+ #ifndef HAVE_sync_compare_and_swapsi
+ #define HAVE_sync_compare_and_swapsi 0
+ #endif
+ #ifndef HAVE_atomic_compare_and_swapsi
+ #define HAVE_atomic_compare_and_swapsi 0
+ #endif
+   if (HAVE_sync_compare_and_swapsi || HAVE_atomic_compare_and_swapsi)
+ {
+   cpp_define (pfile, __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4);
+   have_swap[4] = true;
+ }
+ 
+ #ifndef HAVE_sync_compare_and_swapdi
+ #define HAVE_sync_compare_and_swapdi 0
+ #endif
+ #ifndef HAVE_atomic_compare_and_swapdi
+ #define HAVE_atomic_compare_and_swapdi 0
+ #endif
+   if (HAVE_sync_compare_and_swapdi || HAVE_atomic_compare_and_swapdi)
+ {
+   cpp_define (pfile, __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8);
+   have_swap[8] = true;
+ }
+ 
+ #ifndef HAVE_sync_compare_and_swapti
+ #define HAVE_sync_compare_and_swapti 0
+ #endif
+ #ifndef HAVE_atomic_compare_and_swapti
+ #define HAVE_atomic_compare_and_swapti 0
+ #endif
+   if (HAVE_sync_compare_and_swapti || HAVE_atomic_compare_and_swapti)
+ {
+   cpp_define (pfile, __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16);
+   have_swap[16] = true;
+ }
+ 
+   /* Tell the source code about various types.  These map to the C++11 and C1x
+  macros where 2 indicates lock-free always, and 1 indicates sometimes
+  lock free.  */
+ #define SIZEOF_NODE(T) (tree_low_cst (TYPE_SIZE_UNIT (T), 1))
+ #define SWAP_INDEX(T) ((SIZEOF_NODE (T)  SWAP_LIMIT) ? SIZEOF_NODE (T) : 0)
+   builtin_define_with_int_value (__GCC_ATOMIC_BOOL_LOCK_FREE, 
+   (have_swap[SWAP_INDEX (boolean_type_node)]? 2 : 1));
+   builtin_define_with_int_value (__GCC_ATOMIC_CHAR_LOCK_FREE, 
+   (have_swap[SWAP_INDEX (signed_char_type_node)]? 2 : 1));
+   builtin_define_with_int_value (__GCC_ATOMIC_CHAR16_T_LOCK_FREE, 
+   (have_swap[SWAP_INDEX (char16_type_node)]? 2 : 1));
+   builtin_define_with_int_value (__GCC_ATOMIC_CHAR32_T_LOCK_FREE, 
+   (have_swap[SWAP_INDEX (char32_type_node)]? 2 : 1));
+   builtin_define_with_int_value (__GCC_ATOMIC_WCHAR_T_LOCK_FREE, 
+   (have_swap[SWAP_INDEX (wchar_type_node)]? 2 : 1));
+   

Re: [PATCH] Re: [v3] updated atomic configury

2011-11-28 Thread Richard Henderson
On 11/28/2011 11:29 AM, Andrew MacLeod wrote:
   c-family
   * c-cpp-builtin.c (cpp_atomic_builtins):New.  Emit all atomic
   predefines in one place.  Add LOCK_FREE predefines.
   (c_cpp_builtins): Move Legacy HAVE_SYNC predefines to
   new func.
 
   libstdc++-v3
   * include/bits/atomic_base.h (ATOMIC_*_LOCK_FREE): Use new cpp
   predefined macros.
   * testsuite/29_atomics/headers/atomic/macros.cc: Add BOOL and POINTER
   macro checks.  Check for expected compile time values.

Ok.


r~