[Git][ghc/ghc][master] rts: remove unused HAVE_C11_ATOMICS macro

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Wed Feb 21 10:03:06 UTC 2024



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
1387966a by Cheng Shao at 2024-02-21T05:02:32-05:00
rts: remove unused HAVE_C11_ATOMICS macro

This commit removes the unused HAVE_C11_ATOMICS macro. We used to have
a few places that have fallback paths when HAVE_C11_ATOMICS is not
defined, but that is completely redundant, since the
FP_CC_SUPPORTS__ATOMICS configure check will fail when the C compiler
doesn't support C11 style atomics. There are also many places (e.g. in
unreg backend, SMP.h, library cbits, etc) where we unconditionally use
C11 style atomics anyway which work in even CentOS 7 (gcc 4.8), the
oldest distro we test in our CI, so there's no value in keeping
HAVE_C11_ATOMICS.

- - - - -


5 changed files:

- compiler/cbits/genSym.c
- libraries/ghc-prim/cbits/atomic.c
- rts/configure.ac
- rts/include/rts/TSANUtils.h
- rts/include/stg/SMP.h


Changes:

=====================================
compiler/cbits/genSym.c
=====================================
@@ -20,10 +20,6 @@ HsInt ghc_unique_inc     = 1;
 #if WORD_SIZE_IN_BITS != 64
 StgWord64 atomic_inc64(StgWord64 volatile* p, StgWord64 incr)
 {
-#if defined(HAVE_C11_ATOMICS)
     return __atomic_fetch_add(p, incr, __ATOMIC_SEQ_CST);
-#else
-    return __sync_fetch_and_add(p, incr);
-#endif
 }
 #endif


=====================================
libraries/ghc-prim/cbits/atomic.c
=====================================
@@ -356,44 +356,28 @@ extern StgWord hs_atomicread8(StgWord x);
 StgWord
 hs_atomicread8(StgWord x)
 {
-#if HAVE_C11_ATOMICS
   return __atomic_load_n((StgWord8 *) x, __ATOMIC_SEQ_CST);
-#else
-  return __sync_add_and_fetch((StgWord8 *) x, 0);
-#endif
 }
 
 extern StgWord hs_atomicread16(StgWord x);
 StgWord
 hs_atomicread16(StgWord x)
 {
-#if HAVE_C11_ATOMICS
   return __atomic_load_n((StgWord16 *) x, __ATOMIC_SEQ_CST);
-#else
-  return __sync_add_and_fetch((StgWord16 *) x, 0);
-#endif
 }
 
 extern StgWord hs_atomicread32(StgWord x);
 StgWord
 hs_atomicread32(StgWord x)
 {
-#if HAVE_C11_ATOMICS
   return __atomic_load_n((StgWord32 *) x, __ATOMIC_SEQ_CST);
-#else
-  return __sync_add_and_fetch((StgWord32 *) x, 0);
-#endif
 }
 
 extern StgWord64 hs_atomicread64(StgWord x);
 StgWord64
 hs_atomicread64(StgWord x)
 {
-#if HAVE_C11_ATOMICS
   return __atomic_load_n((StgWord64 *) x, __ATOMIC_SEQ_CST);
-#else
-  return __sync_add_and_fetch((StgWord64 *) x, 0);
-#endif
 }
 
 // AtomicWriteByteArrayOp_Int
@@ -404,44 +388,28 @@ extern void hs_atomicwrite8(StgWord x, StgWord val);
 void
 hs_atomicwrite8(StgWord x, StgWord val)
 {
-#if HAVE_C11_ATOMICS
   __atomic_store_n((StgWord8 *) x, (StgWord8) val, __ATOMIC_SEQ_CST);
-#else
-  while (!__sync_bool_compare_and_swap((StgWord8 *) x, *(StgWord8 *) x, (StgWord8) val));
-#endif
 }
 
 extern void hs_atomicwrite16(StgWord x, StgWord val);
 void
 hs_atomicwrite16(StgWord x, StgWord val)
 {
-#if HAVE_C11_ATOMICS
   __atomic_store_n((StgWord16 *) x, (StgWord16) val, __ATOMIC_SEQ_CST);
-#else
-  while (!__sync_bool_compare_and_swap((StgWord16 *) x, *(StgWord16 *) x, (StgWord16) val));
-#endif
 }
 
 extern void hs_atomicwrite32(StgWord x, StgWord val);
 void
 hs_atomicwrite32(StgWord x, StgWord val)
 {
-#if HAVE_C11_ATOMICS
   __atomic_store_n((StgWord32 *) x, (StgWord32) val, __ATOMIC_SEQ_CST);
-#else
-  while (!__sync_bool_compare_and_swap((StgWord32 *) x, *(StgWord32 *) x, (StgWord32) val));
-#endif
 }
 
 extern void hs_atomicwrite64(StgWord x, StgWord64 val);
 void
 hs_atomicwrite64(StgWord x, StgWord64 val)
 {
-#if HAVE_C11_ATOMICS
   __atomic_store_n((StgWord64 *) x, (StgWord64) val, __ATOMIC_SEQ_CST);
-#else
-  while (!__sync_bool_compare_and_swap((StgWord64 *) x, *(StgWord64 *) x, (StgWord64) val));
-#endif
 }
 
 #endif


=====================================
rts/configure.ac
=====================================
@@ -71,7 +71,6 @@ dnl    unregisterised, Sparc, and PPC backends. Also determines whether
 dnl    linking to libatomic is required for atomic operations, e.g. on
 dnl    RISCV64 GCC.
 FP_CC_SUPPORTS__ATOMICS
-AC_DEFINE([HAVE_C11_ATOMICS], [1], [Does C compiler support __atomic primitives?])
 AC_DEFINE_UNQUOTED([NEED_ATOMIC_LIB], [$need_latomic],
     [Define to 1 if we need -latomic for sub-word atomic operations.])
 


=====================================
rts/include/rts/TSANUtils.h
=====================================
@@ -75,9 +75,6 @@
 
 #if !defined(CMINUSMINUS)
 #if defined(TSAN_ENABLED)
-#if !defined(HAVE_C11_ATOMICS)
-#error TSAN cannot be enabled without C11 atomics support.
-#endif
 
 #define TSAN_ANNOTATE_HAPPENS_BEFORE(addr)                              \
     AnnotateHappensBefore(__FILE__, __LINE__, (void*)(addr))


=====================================
rts/include/stg/SMP.h
=====================================
@@ -442,25 +442,7 @@ EXTERN_INLINE void busy_wait_nop(void);
 EXTERN_INLINE StgWord
 xchg(StgPtr p, StgWord w)
 {
-#if defined(HAVE_C11_ATOMICS)
     return __atomic_exchange_n(p, w, __ATOMIC_SEQ_CST);
-#else
-    // When porting GHC to a new platform check that
-    // __sync_lock_test_and_set() actually stores w in *p.
-    // Use test rts/atomicxchg to verify that the correct value is stored.
-    // From the gcc manual:
-    // (https://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Atomic-Builtins.html)
-    // This built-in function, as described by Intel, is not
-    // a traditional test-and-set operation, but rather an atomic
-    // exchange operation.
-    // [...]
-    // Many targets have only minimal support for such locks,
-    // and do not support a full exchange operation. In this case,
-    // a target may support reduced functionality here by which the
-    // only valid value to store is the immediate constant 1. The
-    // exact value actually stored in *ptr is implementation defined.
-    return __sync_lock_test_and_set(p, w);
-#endif
 }
 
 /*
@@ -470,34 +452,21 @@ xchg(StgPtr p, StgWord w)
 EXTERN_INLINE StgWord
 cas(StgVolatilePtr p, StgWord o, StgWord n)
 {
-#if defined(HAVE_C11_ATOMICS)
     __atomic_compare_exchange_n(p, &o, n, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
     return o;
-#else
-    return __sync_val_compare_and_swap(p, o, n);
-#endif
 }
 
 EXTERN_INLINE StgWord8
 cas_word8(StgWord8 *volatile p, StgWord8 o, StgWord8 n)
 {
-#if defined(HAVE_C11_ATOMICS)
     __atomic_compare_exchange_n(p, &o, n, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
     return o;
-#else
-    return __sync_val_compare_and_swap(p, o, n);
-#endif
 }
 
 EXTERN_INLINE StgWord
 cas_seq_cst_relaxed(StgVolatilePtr p, StgWord o, StgWord n) {
-#if defined(HAVE_C11_ATOMICS)
     __atomic_compare_exchange_n(p, &o, n, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
     return o;
-#else
-    return __sync_val_compare_and_swap(p, o, n);
-#endif
-
 }
 
 // RRN: Generalized to arbitrary increments to enable fetch-and-add in
@@ -506,21 +475,13 @@ cas_seq_cst_relaxed(StgVolatilePtr p, StgWord o, StgWord n) {
 EXTERN_INLINE StgWord
 atomic_inc(StgVolatilePtr p, StgWord incr)
 {
-#if defined(HAVE_C11_ATOMICS)
     return __atomic_add_fetch(p, incr, __ATOMIC_SEQ_CST);
-#else
-    return __sync_add_and_fetch(p, incr);
-#endif
 }
 
 EXTERN_INLINE StgWord
 atomic_dec(StgVolatilePtr p)
 {
-#if defined(HAVE_C11_ATOMICS)
     return __atomic_sub_fetch(p, 1, __ATOMIC_SEQ_CST);
-#else
-    return __sync_sub_and_fetch(p, (StgWord) 1);
-#endif
 }
 
 /*



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1387966ae5ca8fe74e3e281cacc6d39d54e778e0

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1387966ae5ca8fe74e3e281cacc6d39d54e778e0
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240221/fb2236f3/attachment-0001.html>


More information about the ghc-commits mailing list