]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Define __HAVE_64B_ATOMICS from compiler support
authorWilco Dijkstra <Wilco.Dijkstra@arm.com>
Thu, 11 Sep 2025 11:08:17 +0000 (08:08 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 11 Sep 2025 17:44:02 +0000 (14:44 -0300)
Now that atomic builtins are used by default, we can rely on the
compiler to define when to use 64-bit atomic operations.

It allows the use of 64-bit atomic operations on some 32-bit ABIs where
they were not previously enabled due to missing pre-processor handling:
hppa, mips64n32, s390, and sparcv9.

Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
21 files changed:
config.h.in
configure
configure.ac
include/atomic.h
sysdeps/aarch64/atomic-machine.h
sysdeps/alpha/atomic-machine.h
sysdeps/arc/atomic-machine.h
sysdeps/arm/atomic-machine.h
sysdeps/csky/atomic-machine.h
sysdeps/hppa/atomic-machine.h
sysdeps/loongarch/atomic-machine.h
sysdeps/m68k/atomic-machine.h
sysdeps/microblaze/atomic-machine.h
sysdeps/mips/atomic-machine.h
sysdeps/or1k/atomic-machine.h
sysdeps/powerpc/atomic-machine.h
sysdeps/riscv/atomic-machine.h
sysdeps/s390/atomic-machine.h
sysdeps/sh/atomic-machine.h
sysdeps/sparc/atomic-machine.h
sysdeps/x86/atomic-machine.h

index 8b4077f578d57e11ff454930c732d2f129f9533f..da220019204f4adb5ee874fd603c3aa658e79113 100644 (file)
 /* An integer used to scale the timeout of test programs.  */
 #define TIMEOUTFACTOR 1
 
+/* Set to 1 if 64 bit atomics are supported.  */
+#undef __HAVE_64B_ATOMICS 0
+
 /*
 \f */
 
index 222f04db220ddf6849ccd8f40e431233cc9d52db..b7d0d53c604ad8e24636d2e56bd4b086f291337d 100755 (executable)
--- a/configure
+++ b/configure
@@ -7676,6 +7676,48 @@ if test "$libc_cv_gcc_builtin_memset" = yes ; then
 
 fi
 
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for 64-bit atomic support" >&5
+printf %s "checking for 64-bit atomic support... " >&6; }
+if test ${libc_cv_gcc_has_64b_atomics+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e) cat > conftest.c <<\EOF
+typedef struct { long long t; } X;
+extern void has_64b_atomics(void);
+void f(void)
+{
+  X x;
+  /* Use address of structure with 64-bit type.  This avoids incorrect
+     implementations which return true even if long long is not 64-bit aligned.
+     This works on GCC and LLVM - other cases have bugs and they disagree.  */
+  _Static_assert (__atomic_always_lock_free (sizeof (x), &x), "no_64b_atomics");
+}
+EOF
+if { ac_try='${CC-cc} -O2 -S conftest.c'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; };
+then
+  libc_cv_gcc_has_64b_atomics=yes
+else
+  libc_cv_gcc_has_64b_atomics=no
+fi
+rm -f conftest*  ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_gcc_has_64b_atomics" >&5
+printf "%s\n" "$libc_cv_gcc_has_64b_atomics" >&6; }
+if test "$libc_cv_gcc_has_64b_atomics" = yes; then
+  printf "%s\n" "#define __HAVE_64B_ATOMICS 1" >>confdefs.h
+
+else
+  printf "%s\n" "#define __HAVE_64B_ATOMICS 0" >>confdefs.h
+
+ fi
+
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for redirection of built-in functions" >&5
 printf %s "checking for redirection of built-in functions... " >&6; }
 if test ${libc_cv_gcc_builtin_redirection+y}
index af57b0cbae8c1b22bfdc7a4e47d46c4e5064873a..9dacdf5ee6f958420b4dab6d95bc2e298de5b394 100644 (file)
@@ -1484,6 +1484,33 @@ if test "$libc_cv_gcc_builtin_memset" = yes ; then
   AC_DEFINE(HAVE_BUILTIN_MEMSET)
 fi
 
+AC_CACHE_CHECK(for 64-bit atomic support, libc_cv_gcc_has_64b_atomics, [dnl
+cat > conftest.c <<\EOF
+typedef struct { long long t; } X;
+extern void has_64b_atomics(void);
+void f(void)
+{
+  X x;
+  /* Use address of structure with 64-bit type.  This avoids incorrect
+     implementations which return true even if long long is not 64-bit aligned.
+     This works on GCC and LLVM - other cases have bugs and they disagree.  */
+  _Static_assert (__atomic_always_lock_free (sizeof (x), &x), "no_64b_atomics");
+}
+EOF
+dnl
+if AC_TRY_COMMAND([${CC-cc} -O2 -S conftest.c]);
+then
+  libc_cv_gcc_has_64b_atomics=yes
+else
+  libc_cv_gcc_has_64b_atomics=no
+fi
+rm -f conftest* ])
+if test "$libc_cv_gcc_has_64b_atomics" = yes; then
+  AC_DEFINE(__HAVE_64B_ATOMICS, 1)
+else
+  AC_DEFINE(__HAVE_64B_ATOMICS, 0)
+ fi
+
 AC_CACHE_CHECK(for redirection of built-in functions, libc_cv_gcc_builtin_redirection, [dnl
 cat > conftest.c <<\EOF
 extern char *strstr (const char *, const char *) __asm ("my_strstr");
index 07c5324f8b43c62e3dd34d601c04302cf79fd2c7..44abd95d7eb8fbf147be0e5479afe3cb4f1819bc 100644 (file)
   ({ __typeof (x) __x; __asm ("" : "=r" (__x) : "0" (x)); __x; })
 #endif
 
-/* This is equal to 1 iff the architecture supports 64b atomic operations.  */
-#ifndef __HAVE_64B_ATOMICS
-#error Unable to determine if 64-bit atomics are present.
-#endif
-
 /* The following functions are a subset of the atomic operations provided by
    C11.  Usually, a function named atomic_OP_MO(args) is equivalent to C11's
    atomic_OP_explicit(args, memory_order_MO); exceptions noted below.  */
index f00c4607f3210827379f6a3524ffe1cb17ae73f4..002a8003581798e278334247af965e2aa063fa9d 100644 (file)
@@ -19,7 +19,6 @@
 #ifndef _AARCH64_ATOMIC_MACHINE_H
 #define _AARCH64_ATOMIC_MACHINE_H      1
 
-#define __HAVE_64B_ATOMICS 1
 #define ATOMIC_EXCHANGE_USES_CAS 0
 
 #endif
index 198f5dc037cb7d6f923123e84647f40dd3de1721..9844f130799044b8a8bdb69fbea0850950af25bc 100644 (file)
@@ -17,8 +17,6 @@
 
 #include <stdint.h>
 
-#define __HAVE_64B_ATOMICS 1
-
 /* XXX Is this actually correct?  */
 #define ATOMIC_EXCHANGE_USES_CAS 1
 
index 096035840a7eb08512d7c8d924f4bb075a3e7c13..69b9328fc861ba11b72e8053822028d12bd056d9 100644 (file)
@@ -19,8 +19,6 @@
 #ifndef _ARC_BITS_ATOMIC_H
 #define _ARC_BITS_ATOMIC_H 1
 
-#define __HAVE_64B_ATOMICS 0
-
 /* ARC does have legacy atomic EX reg, [mem] instruction but the micro-arch
    is not as optimal as LLOCK/SCOND specially for SMP.  */
 #define ATOMIC_EXCHANGE_USES_CAS 1
index f728de4ba5545684b00b3cb2cf998f23bb55c602..7aee873371f5e6a392056ffdebc8ed62b723a7a5 100644 (file)
@@ -16,5 +16,4 @@
    License along with the GNU C Library.  If not, see
    <https://www.gnu.org/licenses/>.  */
 
-#define __HAVE_64B_ATOMICS 0
 #define ATOMIC_EXCHANGE_USES_CAS 1
index 5d6f3d19ce93b8342a0606245fd679ec666b3e2c..84468cd66ec3519e014c5d61bffd6b24679c6fc8 100644 (file)
@@ -19,7 +19,6 @@
 #ifndef __CSKY_ATOMIC_H_
 #define __CSKY_ATOMIC_H_
 
-#define __HAVE_64B_ATOMICS 0
 #define ATOMIC_EXCHANGE_USES_CAS 1
 
 #endif /* atomic-machine.h */
index 839b8df59659a0410d32c90fe849f6f9d8afbb1e..92d386b7488b84d9cefcc2b4e711f93f2f1e77ec 100644 (file)
@@ -18,8 +18,6 @@
 #ifndef _ATOMIC_MACHINE_H
 #define _ATOMIC_MACHINE_H      1
 
-#define __HAVE_64B_ATOMICS 0
-
 /* XXX Is this actually correct?  */
 #define ATOMIC_EXCHANGE_USES_CAS 1
 
index 7e10309932e488a9ed136379e7bf96872ba3c33b..20cc170735d789fa508a7543b508137c1ba2a7d2 100644 (file)
@@ -19,7 +19,6 @@
 #ifndef _LINUX_LOONGARCH_BITS_ATOMIC_H
 #define _LINUX_LOONGARCH_BITS_ATOMIC_H 1
 
-#define __HAVE_64B_ATOMICS (__loongarch_grlen >= 64)
 #define ATOMIC_EXCHANGE_USES_CAS 0
 
 #endif /* bits/atomic.h */
index 9242f6eec26a89fc62a439d7de8064132ed1c011..8542affba031b7872cc3befd93938eeeab4b953c 100644 (file)
@@ -19,8 +19,6 @@
 #define _M68K_ATOMIC_MACHINE_H 1
 
 #if defined __mc68020__ || defined __mcoldfire__
-# define __HAVE_64B_ATOMICS 0
-
 /* XXX Is this actually correct?  */
 # define ATOMIC_EXCHANGE_USES_CAS 1
 #else
index d5f6f7e46200fc07cbe78e5ff2b1a11a602aceb9..8c04235b69eb004c5c3cdd9c9d48b7e95904884b 100644 (file)
@@ -18,7 +18,5 @@
 
 #include <sysdep.h>
 
-#define __HAVE_64B_ATOMICS 0
-
 /* XXX Is this actually correct?  */
 #define ATOMIC_EXCHANGE_USES_CAS 1
index f19310006bbea92659f390e26237d043836a0051..9294fb76d934acae5e20c1132ba9d36c44b990c9 100644 (file)
 #define MIPS_PUSH_MIPS2
 #endif
 
-#if _MIPS_SIM == _ABIO32 || _MIPS_SIM == _ABIN32
-#define __HAVE_64B_ATOMICS 0
-#else
-#define __HAVE_64B_ATOMICS 1
-#endif
-
 /* MIPS is an LL/SC machine.  However, XLP has a direct atomic exchange
    instruction which will be used by __atomic_exchange_n.  */
 #ifdef _MIPS_ARCH_XLP
index 8dac0e4cedfc4217f7968d1631f46324be4da29a..51bc8a0ff4f5bd3a72794018c01aa8faf5cb98f1 100644 (file)
@@ -19,7 +19,6 @@
 #ifndef __OR1K_ATOMIC_H_
 #define __OR1K_ATOMIC_H_
 
-#define __HAVE_64B_ATOMICS 0
 #define ATOMIC_EXCHANGE_USES_CAS 1
 
 #endif /* atomic-machine.h */
index e32408a09d63ca2952310ec48d6673698191f976..988cc4f4359e7cfab15dc849ceb1566865cc0e10 100644 (file)
 #ifndef _POWERPC_ATOMIC_MACHINE_H
 #define _POWERPC_ATOMIC_MACHINE_H       1
 
-#if __WORDSIZE == 64
-# define __HAVE_64B_ATOMICS 1
-#else
-# define __HAVE_64B_ATOMICS 0
-#endif
 #define ATOMIC_EXCHANGE_USES_CAS 1
 
 /* Used on pthread_spin_{try}lock.  */
index c5d39c1be743f48fe04d622e3a44ad9bee527a84..5d2ad331cc97a58c1f997501d6f9f8903440742b 100644 (file)
@@ -21,7 +21,6 @@
 
 #ifdef __riscv_atomic
 
-# define __HAVE_64B_ATOMICS (__riscv_xlen >= 64)
 # define ATOMIC_EXCHANGE_USES_CAS 0
 
 /* Miscellaneous.  */
index 6f20dce80253ec94624727c73a5ad14a68156112..b1646d1b07c9c6e1c0504a4f4e3964b5e2781c8a 100644 (file)
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#ifdef __s390x__
-# define __HAVE_64B_ATOMICS 1
-#else
-# define __HAVE_64B_ATOMICS 0
-#endif
-
 #define ATOMIC_EXCHANGE_USES_CAS 1
index b4ed894bdbda2e34a2920496281e69961a9df64c..b012d6f05626fd8c3cb1a98636a926b9d98fc32a 100644 (file)
@@ -16,7 +16,5 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#define __HAVE_64B_ATOMICS 0
-
 /* XXX Is this actually correct?  */
 #define ATOMIC_EXCHANGE_USES_CAS 1
index a00d2ad1d370b4a8d9f16cad6424f2333df273a1..a16f18fe571e65be1e533cbe2b5e8139663b3e35 100644 (file)
 #ifndef _ATOMIC_MACHINE_H
 #define _ATOMIC_MACHINE_H      1
 
-#ifdef __arch64__
-# define __HAVE_64B_ATOMICS          1
-#else
-# define __HAVE_64B_ATOMICS          0
-#endif
-
 /* XXX Is this actually correct?  */
 #define ATOMIC_EXCHANGE_USES_CAS     __HAVE_64B_ATOMICS
 
index 0051eede7040110f96a27cf1ac28fe56cf69af1b..7c2ebfcee1891c31af36d716b31c6048253dacaf 100644 (file)
 #ifndef _X86_ATOMIC_MACHINE_H
 #define _X86_ATOMIC_MACHINE_H 1
 
-#ifdef __x86_64__
-# define __HAVE_64B_ATOMICS            1
-#else
-/* Since the Pentium, i386 CPUs have supported 64-bit atomics, but the
-   i386 psABI supplement provides only 4-byte alignment for uint64_t
-   inside structs, so it is currently not possible to use 64-bit
-   atomics on this platform.  */
-# define __HAVE_64B_ATOMICS            0
-#endif
-
 #define ATOMIC_EXCHANGE_USES_CAS       0
 
 #define atomic_spin_nop() __asm ("pause")