bca718
Backporting the C11 atomic support will allow future algorithms
bca718
to be more easily backported to RHEL7. This is initially backported
bca718
to support the new semaphore algorithm which is now in RHEL7
bca718
(rhbz#1027348).
bca718
bca718
commit 1ea339b69725cb2f30b5a84cb7ca96111c9a637b
bca718
Author: Torvald Riegel <triegel@redhat.com>
bca718
Date:   Sat Oct 18 01:02:59 2014 +0200
bca718
bca718
    Add arch-specific configuration for C11 atomics support.
bca718
    
bca718
    This sets __HAVE_64B_ATOMICS if provided.  It also sets
bca718
    USE_ATOMIC_COMPILER_BUILTINS to true if the existing atomic ops use the
bca718
    __atomic* builtins (aarch64, mips partially) or if this has been
bca718
    tested (x86_64); otherwise, this is set to false so that C11 atomics will
bca718
    be based on the existing atomic operations.
bca718
bca718
Index: glibc-2.17-c758a686/ports/sysdeps/aarch64/bits/atomic.h
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/ports/sysdeps/aarch64/bits/atomic.h
bca718
+++ glibc-2.17-c758a686/ports/sysdeps/aarch64/bits/atomic.h
bca718
@@ -36,6 +36,8 @@ typedef uintptr_t uatomicptr_t;
bca718
 typedef intmax_t atomic_max_t;
bca718
 typedef uintmax_t uatomic_max_t;
bca718
 
bca718
+#define __HAVE_64B_ATOMICS 1
bca718
+#define USE_ATOMIC_COMPILER_BUILTINS 1
bca718
 
bca718
 /* Compare and exchange.
bca718
    For all "bool" routines, we return FALSE if exchange succesful.  */
bca718
Index: glibc-2.17-c758a686/ports/sysdeps/alpha/bits/atomic.h
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/ports/sysdeps/alpha/bits/atomic.h
bca718
+++ glibc-2.17-c758a686/ports/sysdeps/alpha/bits/atomic.h
bca718
@@ -42,6 +42,9 @@ typedef uintptr_t uatomicptr_t;
bca718
 typedef intmax_t atomic_max_t;
bca718
 typedef uintmax_t uatomic_max_t;
bca718
 
bca718
+#define __HAVE_64B_ATOMICS 1
bca718
+#define USE_ATOMIC_COMPILER_BUILTINS 0
bca718
+
bca718
 
bca718
 #ifdef UP
bca718
 # define __MB		/* nothing */
bca718
Index: glibc-2.17-c758a686/ports/sysdeps/arm/bits/atomic.h
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/ports/sysdeps/arm/bits/atomic.h
bca718
+++ glibc-2.17-c758a686/ports/sysdeps/arm/bits/atomic.h
bca718
@@ -33,6 +33,9 @@ typedef uintptr_t uatomicptr_t;
bca718
 typedef intmax_t atomic_max_t;
bca718
 typedef uintmax_t uatomic_max_t;
bca718
 
bca718
+#define __HAVE_64B_ATOMICS 0
bca718
+#define USE_ATOMIC_COMPILER_BUILTINS 0
bca718
+
bca718
 void __arm_link_error (void);
bca718
 
bca718
 /* Use the atomic builtins provided by GCC in case the backend provides
bca718
Index: glibc-2.17-c758a686/sysdeps/i386/i486/bits/atomic.h
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/sysdeps/i386/i486/bits/atomic.h
bca718
+++ glibc-2.17-c758a686/sysdeps/i386/i486/bits/atomic.h
bca718
@@ -54,6 +54,9 @@ typedef uintmax_t uatomic_max_t;
bca718
 # endif
bca718
 #endif
bca718
 
bca718
+#define __HAVE_64B_ATOMICS 0
bca718
+#define USE_ATOMIC_COMPILER_BUILTINS 0
bca718
+
bca718
 
bca718
 #define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \
bca718
   __sync_val_compare_and_swap (mem, oldval, newval)
bca718
Index: glibc-2.17-c758a686/ports/sysdeps/ia64/bits/atomic.h
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/ports/sysdeps/ia64/bits/atomic.h
bca718
+++ glibc-2.17-c758a686/ports/sysdeps/ia64/bits/atomic.h
bca718
@@ -43,6 +43,9 @@ typedef uintptr_t uatomicptr_t;
bca718
 typedef intmax_t atomic_max_t;
bca718
 typedef uintmax_t uatomic_max_t;
bca718
 
bca718
+#define __HAVE_64B_ATOMICS 1
bca718
+#define USE_ATOMIC_COMPILER_BUILTINS 0
bca718
+
bca718
 
bca718
 #define __arch_compare_and_exchange_bool_8_acq(mem, newval, oldval) \
bca718
   (abort (), 0)
bca718
Index: glibc-2.17-c758a686/ports/sysdeps/m68k/coldfire/bits/atomic.h
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/ports/sysdeps/m68k/coldfire/bits/atomic.h
bca718
+++ glibc-2.17-c758a686/ports/sysdeps/m68k/coldfire/bits/atomic.h
bca718
@@ -49,6 +49,10 @@ typedef uintptr_t uatomicptr_t;
bca718
 typedef intmax_t atomic_max_t;
bca718
 typedef uintmax_t uatomic_max_t;
bca718
 
bca718
+/* If we have just non-atomic operations, we can as well make them wide.  */
bca718
+#define __HAVE_64B_ATOMICS 1
bca718
+#define USE_ATOMIC_COMPILER_BUILTINS 0
bca718
+
bca718
 /* The only basic operation needed is compare and exchange.  */
bca718
 #define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \
bca718
   ({ __typeof (mem) __gmemp = (mem);				      \
bca718
Index: glibc-2.17-c758a686/ports/sysdeps/m68k/m680x0/m68020/bits/atomic.h
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/ports/sysdeps/m68k/m680x0/m68020/bits/atomic.h
bca718
+++ glibc-2.17-c758a686/ports/sysdeps/m68k/m680x0/m68020/bits/atomic.h
bca718
@@ -44,6 +44,9 @@ typedef uintptr_t uatomicptr_t;
bca718
 typedef intmax_t atomic_max_t;
bca718
 typedef uintmax_t uatomic_max_t;
bca718
 
bca718
+#define __HAVE_64B_ATOMICS 1
bca718
+#define USE_ATOMIC_COMPILER_BUILTINS 0
bca718
+
bca718
 #define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
bca718
   ({ __typeof (*(mem)) __ret;						      \
bca718
      __asm __volatile ("cas%.b %0,%2,%1"				      \
bca718
Index: glibc-2.17-c758a686/ports/sysdeps/mips/bits/atomic.h
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/ports/sysdeps/mips/bits/atomic.h
bca718
+++ glibc-2.17-c758a686/ports/sysdeps/mips/bits/atomic.h
bca718
@@ -43,6 +43,12 @@ typedef uintmax_t uatomic_max_t;
bca718
 #define MIPS_PUSH_MIPS2
bca718
 #endif
bca718
 
bca718
+#if _MIPS_SIM == _ABIO32
bca718
+#define __HAVE_64B_ATOMICS 0
bca718
+#else
bca718
+#define __HAVE_64B_ATOMICS 1
bca718
+#endif
bca718
+
bca718
 /* See the comments in <sys/asm.h> about the use of the sync instruction.  */
bca718
 #ifndef MIPS_SYNC
bca718
 # define MIPS_SYNC	sync
bca718
@@ -82,6 +88,8 @@ typedef uintmax_t uatomic_max_t;
bca718
 /* The __atomic_* builtins are available in GCC 4.7 and later, but MIPS
bca718
    support for their efficient implementation was added only in GCC 4.8.  */
bca718
 
bca718
+#define USE_ATOMIC_COMPILER_BUILTINS 1
bca718
+
bca718
 /* Compare and exchange.
bca718
    For all "bool" routines, we return FALSE if exchange succesful.  */
bca718
 
bca718
@@ -204,6 +212,8 @@ typedef uintmax_t uatomic_max_t;
bca718
 /* This implementation using inline assembly will be removed once glibc
bca718
    requires GCC 4.8 or later to build.  */
bca718
 
bca718
+#define USE_ATOMIC_COMPILER_BUILTINS 0
bca718
+
bca718
 /* Compare and exchange.  For all of the "xxx" routines, we expect a
bca718
    "__prev" and a "__cmp" variable to be provided by the enclosing scope,
bca718
    in which values are returned.  */
bca718
Index: glibc-2.17-c758a686/sysdeps/powerpc/powerpc32/bits/atomic.h
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/sysdeps/powerpc/powerpc32/bits/atomic.h
bca718
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc32/bits/atomic.h
bca718
@@ -33,6 +33,9 @@
bca718
 # define MUTEX_HINT_REL
bca718
 #endif
bca718
 
bca718
+#define __HAVE_64B_ATOMICS 0
bca718
+#define USE_ATOMIC_COMPILER_BUILTINS 0
bca718
+
bca718
 /*
bca718
  * The 32-bit exchange_bool is different on powerpc64 because the subf
bca718
  * does signed 64-bit arthmatic while the lwarx is 32-bit unsigned
bca718
Index: glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/bits/atomic.h
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/sysdeps/powerpc/powerpc64/bits/atomic.h
bca718
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/bits/atomic.h
bca718
@@ -33,6 +33,9 @@
bca718
 # define MUTEX_HINT_REL
bca718
 #endif
bca718
 
bca718
+#define __HAVE_64B_ATOMICS 1
bca718
+#define USE_ATOMIC_COMPILER_BUILTINS 0
bca718
+
bca718
 /* The 32-bit exchange_bool is different on powerpc64 because the subf
bca718
    does signed 64-bit arthmatic while the lwarx is 32-bit unsigned
bca718
    (a load word and zero (high 32) form) load.
bca718
Index: glibc-2.17-c758a686/sysdeps/s390/bits/atomic.h
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/sysdeps/s390/bits/atomic.h
bca718
+++ glibc-2.17-c758a686/sysdeps/s390/bits/atomic.h
bca718
@@ -43,6 +43,8 @@ typedef uintptr_t uatomicptr_t;
bca718
 typedef intmax_t atomic_max_t;
bca718
 typedef uintmax_t uatomic_max_t;
bca718
 
bca718
+#define USE_ATOMIC_COMPILER_BUILTINS 0
bca718
+
bca718
 
bca718
 #define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
bca718
   (abort (), (__typeof (*mem)) 0)
bca718
@@ -59,6 +61,7 @@ typedef uintmax_t uatomic_max_t;
bca718
      __archold; })
bca718
 
bca718
 #ifdef __s390x__
bca718
+# define __HAVE_64B_ATOMICS 1
bca718
 # define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
bca718
   ({ __typeof (mem) __archmem = (mem);					      \
bca718
      __typeof (*mem) __archold = (oldval);				      \
bca718
@@ -67,6 +70,7 @@ typedef uintmax_t uatomic_max_t;
bca718
 		       : "d" ((long) (newval)), "m" (*__archmem) : "cc", "memory" );    \
bca718
      __archold; })
bca718
 #else
bca718
+# define __HAVE_64B_ATOMICS 0
bca718
 /* For 31 bit we do not really need 64-bit compare-and-exchange. We can
bca718
    implement them by use of the csd instruction. The straightforward
bca718
    implementation causes warnings so we skip the definition for now.  */
bca718
Index: glibc-2.17-c758a686/sysdeps/sparc/sparc32/bits/atomic.h
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/sysdeps/sparc/sparc32/bits/atomic.h
bca718
+++ glibc-2.17-c758a686/sysdeps/sparc/sparc32/bits/atomic.h
bca718
@@ -47,6 +47,9 @@ typedef uintptr_t uatomicptr_t;
bca718
 typedef intmax_t atomic_max_t;
bca718
 typedef uintmax_t uatomic_max_t;
bca718
 
bca718
+#define __HAVE_64B_ATOMICS 0
bca718
+#define USE_ATOMIC_COMPILER_BUILTINS 0
bca718
+
bca718
 
bca718
 /* We have no compare and swap, just test and set.
bca718
    The following implementation contends on 64 global locks
bca718
Index: glibc-2.17-c758a686/sysdeps/sparc/sparc32/sparcv9/bits/atomic.h
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/sysdeps/sparc/sparc32/sparcv9/bits/atomic.h
bca718
+++ glibc-2.17-c758a686/sysdeps/sparc/sparc32/sparcv9/bits/atomic.h
bca718
@@ -44,6 +44,9 @@ typedef uintptr_t uatomicptr_t;
bca718
 typedef intmax_t atomic_max_t;
bca718
 typedef uintmax_t uatomic_max_t;
bca718
 
bca718
+#define __HAVE_64B_ATOMICS 0
bca718
+#define USE_ATOMIC_COMPILER_BUILTINS 0
bca718
+
bca718
 
bca718
 #define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
bca718
   (abort (), (__typeof (*mem)) 0)
bca718
Index: glibc-2.17-c758a686/sysdeps/sparc/sparc64/bits/atomic.h
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/sysdeps/sparc/sparc64/bits/atomic.h
bca718
+++ glibc-2.17-c758a686/sysdeps/sparc/sparc64/bits/atomic.h
bca718
@@ -44,6 +44,9 @@ typedef uintptr_t uatomicptr_t;
bca718
 typedef intmax_t atomic_max_t;
bca718
 typedef uintmax_t uatomic_max_t;
bca718
 
bca718
+#define __HAVE_64B_ATOMICS 1
bca718
+#define USE_ATOMIC_COMPILER_BUILTINS 0
bca718
+
bca718
 
bca718
 #define __arch_compare_and_exchange_val_8_acq(mem, newval, oldval) \
bca718
   (abort (), (__typeof (*mem)) 0)
bca718
Index: glibc-2.17-c758a686/ports/sysdeps/unix/sysv/linux/hppa/bits/atomic.h
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/ports/sysdeps/unix/sysv/linux/hppa/bits/atomic.h
bca718
+++ glibc-2.17-c758a686/ports/sysdeps/unix/sysv/linux/hppa/bits/atomic.h
bca718
@@ -44,6 +44,9 @@ typedef uintptr_t uatomicptr_t;
bca718
 typedef intmax_t atomic_max_t;
bca718
 typedef uintmax_t uatomic_max_t;
bca718
 
bca718
+#define __HAVE_64B_ATOMICS 0
bca718
+#define USE_ATOMIC_COMPILER_BUILTINS 0
bca718
+
bca718
 /* prev = *addr;
bca718
    if (prev == old)
bca718
      *addr = new;
bca718
Index: glibc-2.17-c758a686/sysdeps/x86_64/bits/atomic.h
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/bits/atomic.h
bca718
+++ glibc-2.17-c758a686/sysdeps/x86_64/bits/atomic.h
bca718
@@ -55,6 +55,12 @@ typedef uintmax_t uatomic_max_t;
bca718
 # endif
bca718
 #endif
bca718
 
bca718
+#define __HAVE_64B_ATOMICS 1
bca718
+#if __GNUC_PREREQ (4, 7)
bca718
+#define USE_ATOMIC_COMPILER_BUILTINS 1
bca718
+#else
bca718
+#define USE_ATOMIC_COMPILER_BUILTINS 0
bca718
+#endif
bca718
 
bca718
 #define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \
bca718
   __sync_val_compare_and_swap (mem, oldval, newval)