summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2020-06-19 22:57:53 +0300
committerIvan Maidanski <ivmai@mail.ru>2021-09-09 08:33:10 +0300
commitce2a4df9086f3c603b79d01290bfa89f5f055f73 (patch)
treeda232fdb7bf685d92eaec6b3e61cf8eda7bd8d22
parent48168a6d455c2fd2f6f19c8f1ae3b1ed4dbfcbbc (diff)
downloadlibatomic_ops-ce2a4df9086f3c603b79d01290bfa89f5f055f73.tar.gz
Fix link fail caused by missing GCC char/short atomic primitives on riscv64
Issue #46 (libatomic_ops). gcc/riscv requires the client to add -latomic (or -pthread) flag if char- or short-width compare-and-swap or an arithmetic primitive is used. To avoid such a requirement, the corresponding AO primitives are not provided for now unless AO_PREFER_BUILTIN_ATOMICS is defined. * src/atomic_ops/sysdeps/gcc/generic-arithm.h: Regenerate. * src/atomic_ops/sysdeps/gcc/generic-arithm.template (AO_XSIZE_fetch_and_add_XBAR): Do not define if AO_NO_XSIZE_ARITHM. * src/atomic_ops/sysdeps/gcc/generic-arithm.template [!AO_SKIPATOMIC_ANY_and_ANY] (AO_XSIZE_and_XBAR): Likewise. * src/atomic_ops/sysdeps/gcc/generic-arithm.template [!AO_SKIPATOMIC_ANY_or_ANY] (AO_XSIZE_or_XBAR): Likewise. * src/atomic_ops/sysdeps/gcc/generic-arithm.template [!AO_SKIPATOMIC_ANY_xor_ANY] (AO_XSIZE_xor_XBAR): Likewise. * src/atomic_ops/sysdeps/gcc/riscv.h (AO_GCC_FORCE_HAVE_CAS): Define only if __clang__ or AO_PREFER_BUILTIN_ATOMICS; update comment. * src/atomic_ops/sysdeps/gcc/riscv.h [!__clang__ && !AO_PREFER_BUILTIN_ATOMICS && !__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1] (AO_NO_char_ARITHM): Define macro; add comment. * src/atomic_ops/sysdeps/gcc/riscv.h [!__clang__ && !AO_PREFER_BUILTIN_ATOMICS && !__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2] (AO_NO_short_ARITHM): Likewise. * src/atomic_ops/sysdeps/gcc/riscv.h (AO_NO_char_ARITHM, AO_NO_short_ARITHM): Undefine after include generic.h.
-rw-r--r--src/atomic_ops/sysdeps/gcc/generic-arithm.h64
-rw-r--r--src/atomic_ops/sysdeps/gcc/generic-arithm.template4
-rw-r--r--src/atomic_ops/sysdeps/gcc/riscv.h22
3 files changed, 84 insertions, 6 deletions
diff --git a/src/atomic_ops/sysdeps/gcc/generic-arithm.h b/src/atomic_ops/sysdeps/gcc/generic-arithm.h
index f7f3878..2688328 100644
--- a/src/atomic_ops/sysdeps/gcc/generic-arithm.h
+++ b/src/atomic_ops/sysdeps/gcc/generic-arithm.h
@@ -15,6 +15,8 @@
*
*/
+#ifndef AO_NO_char_ARITHM
+
AO_INLINE unsigned/**/char
AO_char_fetch_and_add(volatile unsigned/**/char *addr, unsigned/**/char incr)
{
@@ -48,6 +50,8 @@ AO_char_fetch_and_add(volatile unsigned/**/char *addr, unsigned/**/char incr)
}
# define AO_HAVE_char_xor
#endif
+
+#endif /* !AO_NO_char_ARITHM */
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
@@ -65,6 +69,8 @@ AO_char_fetch_and_add(volatile unsigned/**/char *addr, unsigned/**/char incr)
*
*/
+#ifndef AO_NO_short_ARITHM
+
AO_INLINE unsigned/**/short
AO_short_fetch_and_add(volatile unsigned/**/short *addr, unsigned/**/short incr)
{
@@ -98,6 +104,8 @@ AO_short_fetch_and_add(volatile unsigned/**/short *addr, unsigned/**/short incr)
}
# define AO_HAVE_short_xor
#endif
+
+#endif /* !AO_NO_short_ARITHM */
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
@@ -115,6 +123,8 @@ AO_short_fetch_and_add(volatile unsigned/**/short *addr, unsigned/**/short incr)
*
*/
+#ifndef AO_NO_int_ARITHM
+
AO_INLINE unsigned
AO_int_fetch_and_add(volatile unsigned *addr, unsigned incr)
{
@@ -148,6 +158,8 @@ AO_int_fetch_and_add(volatile unsigned *addr, unsigned incr)
}
# define AO_HAVE_int_xor
#endif
+
+#endif /* !AO_NO_int_ARITHM */
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
@@ -165,6 +177,8 @@ AO_int_fetch_and_add(volatile unsigned *addr, unsigned incr)
*
*/
+#ifndef AO_NO_ARITHM
+
AO_INLINE AO_t
AO_fetch_and_add(volatile AO_t *addr, AO_t incr)
{
@@ -198,6 +212,8 @@ AO_fetch_and_add(volatile AO_t *addr, AO_t incr)
}
# define AO_HAVE_xor
#endif
+
+#endif /* !AO_NO_ARITHM */
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
@@ -215,6 +231,8 @@ AO_fetch_and_add(volatile AO_t *addr, AO_t incr)
*
*/
+#ifndef AO_NO_char_ARITHM
+
AO_INLINE unsigned/**/char
AO_char_fetch_and_add_acquire(volatile unsigned/**/char *addr, unsigned/**/char incr)
{
@@ -248,6 +266,8 @@ AO_char_fetch_and_add_acquire(volatile unsigned/**/char *addr, unsigned/**/char
}
# define AO_HAVE_char_xor_acquire
#endif
+
+#endif /* !AO_NO_char_ARITHM */
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
@@ -265,6 +285,8 @@ AO_char_fetch_and_add_acquire(volatile unsigned/**/char *addr, unsigned/**/char
*
*/
+#ifndef AO_NO_short_ARITHM
+
AO_INLINE unsigned/**/short
AO_short_fetch_and_add_acquire(volatile unsigned/**/short *addr, unsigned/**/short incr)
{
@@ -298,6 +320,8 @@ AO_short_fetch_and_add_acquire(volatile unsigned/**/short *addr, unsigned/**/sho
}
# define AO_HAVE_short_xor_acquire
#endif
+
+#endif /* !AO_NO_short_ARITHM */
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
@@ -315,6 +339,8 @@ AO_short_fetch_and_add_acquire(volatile unsigned/**/short *addr, unsigned/**/sho
*
*/
+#ifndef AO_NO_int_ARITHM
+
AO_INLINE unsigned
AO_int_fetch_and_add_acquire(volatile unsigned *addr, unsigned incr)
{
@@ -348,6 +374,8 @@ AO_int_fetch_and_add_acquire(volatile unsigned *addr, unsigned incr)
}
# define AO_HAVE_int_xor_acquire
#endif
+
+#endif /* !AO_NO_int_ARITHM */
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
@@ -365,6 +393,8 @@ AO_int_fetch_and_add_acquire(volatile unsigned *addr, unsigned incr)
*
*/
+#ifndef AO_NO_ARITHM
+
AO_INLINE AO_t
AO_fetch_and_add_acquire(volatile AO_t *addr, AO_t incr)
{
@@ -398,6 +428,8 @@ AO_fetch_and_add_acquire(volatile AO_t *addr, AO_t incr)
}
# define AO_HAVE_xor_acquire
#endif
+
+#endif /* !AO_NO_ARITHM */
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
@@ -415,6 +447,8 @@ AO_fetch_and_add_acquire(volatile AO_t *addr, AO_t incr)
*
*/
+#ifndef AO_NO_char_ARITHM
+
AO_INLINE unsigned/**/char
AO_char_fetch_and_add_release(volatile unsigned/**/char *addr, unsigned/**/char incr)
{
@@ -448,6 +482,8 @@ AO_char_fetch_and_add_release(volatile unsigned/**/char *addr, unsigned/**/char
}
# define AO_HAVE_char_xor_release
#endif
+
+#endif /* !AO_NO_char_ARITHM */
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
@@ -465,6 +501,8 @@ AO_char_fetch_and_add_release(volatile unsigned/**/char *addr, unsigned/**/char
*
*/
+#ifndef AO_NO_short_ARITHM
+
AO_INLINE unsigned/**/short
AO_short_fetch_and_add_release(volatile unsigned/**/short *addr, unsigned/**/short incr)
{
@@ -498,6 +536,8 @@ AO_short_fetch_and_add_release(volatile unsigned/**/short *addr, unsigned/**/sho
}
# define AO_HAVE_short_xor_release
#endif
+
+#endif /* !AO_NO_short_ARITHM */
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
@@ -515,6 +555,8 @@ AO_short_fetch_and_add_release(volatile unsigned/**/short *addr, unsigned/**/sho
*
*/
+#ifndef AO_NO_int_ARITHM
+
AO_INLINE unsigned
AO_int_fetch_and_add_release(volatile unsigned *addr, unsigned incr)
{
@@ -548,6 +590,8 @@ AO_int_fetch_and_add_release(volatile unsigned *addr, unsigned incr)
}
# define AO_HAVE_int_xor_release
#endif
+
+#endif /* !AO_NO_int_ARITHM */
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
@@ -565,6 +609,8 @@ AO_int_fetch_and_add_release(volatile unsigned *addr, unsigned incr)
*
*/
+#ifndef AO_NO_ARITHM
+
AO_INLINE AO_t
AO_fetch_and_add_release(volatile AO_t *addr, AO_t incr)
{
@@ -598,6 +644,8 @@ AO_fetch_and_add_release(volatile AO_t *addr, AO_t incr)
}
# define AO_HAVE_xor_release
#endif
+
+#endif /* !AO_NO_ARITHM */
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
@@ -615,6 +663,8 @@ AO_fetch_and_add_release(volatile AO_t *addr, AO_t incr)
*
*/
+#ifndef AO_NO_char_ARITHM
+
AO_INLINE unsigned/**/char
AO_char_fetch_and_add_full(volatile unsigned/**/char *addr, unsigned/**/char incr)
{
@@ -648,6 +698,8 @@ AO_char_fetch_and_add_full(volatile unsigned/**/char *addr, unsigned/**/char inc
}
# define AO_HAVE_char_xor_full
#endif
+
+#endif /* !AO_NO_char_ARITHM */
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
@@ -665,6 +717,8 @@ AO_char_fetch_and_add_full(volatile unsigned/**/char *addr, unsigned/**/char inc
*
*/
+#ifndef AO_NO_short_ARITHM
+
AO_INLINE unsigned/**/short
AO_short_fetch_and_add_full(volatile unsigned/**/short *addr, unsigned/**/short incr)
{
@@ -698,6 +752,8 @@ AO_short_fetch_and_add_full(volatile unsigned/**/short *addr, unsigned/**/short
}
# define AO_HAVE_short_xor_full
#endif
+
+#endif /* !AO_NO_short_ARITHM */
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
@@ -715,6 +771,8 @@ AO_short_fetch_and_add_full(volatile unsigned/**/short *addr, unsigned/**/short
*
*/
+#ifndef AO_NO_int_ARITHM
+
AO_INLINE unsigned
AO_int_fetch_and_add_full(volatile unsigned *addr, unsigned incr)
{
@@ -748,6 +806,8 @@ AO_int_fetch_and_add_full(volatile unsigned *addr, unsigned incr)
}
# define AO_HAVE_int_xor_full
#endif
+
+#endif /* !AO_NO_int_ARITHM */
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
@@ -765,6 +825,8 @@ AO_int_fetch_and_add_full(volatile unsigned *addr, unsigned incr)
*
*/
+#ifndef AO_NO_ARITHM
+
AO_INLINE AO_t
AO_fetch_and_add_full(volatile AO_t *addr, AO_t incr)
{
@@ -798,3 +860,5 @@ AO_fetch_and_add_full(volatile AO_t *addr, AO_t incr)
}
# define AO_HAVE_xor_full
#endif
+
+#endif /* !AO_NO_ARITHM */
diff --git a/src/atomic_ops/sysdeps/gcc/generic-arithm.template b/src/atomic_ops/sysdeps/gcc/generic-arithm.template
index 41e56bf..916d133 100644
--- a/src/atomic_ops/sysdeps/gcc/generic-arithm.template
+++ b/src/atomic_ops/sysdeps/gcc/generic-arithm.template
@@ -15,6 +15,8 @@
*
*/
+#ifndef AO_NO_XSIZE_ARITHM
+
AO_INLINE XCTYPE
AO_XSIZE_fetch_and_add_XBAR(volatile XCTYPE *addr, XCTYPE incr)
{
@@ -48,3 +50,5 @@ AO_XSIZE_fetch_and_add_XBAR(volatile XCTYPE *addr, XCTYPE incr)
}
# define AO_HAVE_XSIZE_xor_XBAR
#endif
+
+#endif /* !AO_NO_XSIZE_ARITHM */
diff --git a/src/atomic_ops/sysdeps/gcc/riscv.h b/src/atomic_ops/sysdeps/gcc/riscv.h
index ce72816..9a0586a 100644
--- a/src/atomic_ops/sysdeps/gcc/riscv.h
+++ b/src/atomic_ops/sysdeps/gcc/riscv.h
@@ -9,14 +9,24 @@
* modified is included with the above copyright notice.
*/
-/* As of gcc-7.2.0, some __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n are missing. */
-/* The operations are lock-free (even for the types smaller than word). */
-#define AO_GCC_FORCE_HAVE_CAS
+#if defined(__clang__) || defined(AO_PREFER_BUILTIN_ATOMICS)
+ /* All __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros are still missing. */
+ /* The operations are lock-free even for the types smaller than word. */
+# define AO_GCC_FORCE_HAVE_CAS
+#else
-/* While double-word atomic operations are provided by the compiler */
-/* (which requires -latomic currently), they are not lock-free as */
-/* riscv itself does not have the double-word atomic operations. */
+ /* As of gcc-7.5, CAS and arithmetic atomic operations for char and */
+ /* short are supported by the compiler but require -latomic flag. */
+# if !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1)
+# define AO_NO_char_ARITHM
+# endif
+# if !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2)
+# define AO_NO_short_ARITHM
+# endif
+#endif /* !__clang__ */
#include "generic.h"
#undef AO_GCC_FORCE_HAVE_CAS
+#undef AO_NO_char_ARITHM
+#undef AO_NO_short_ARITHM