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