diff options
-rw-r--r-- | src/atomic_ops/sysdeps/gcc/generic-arithm.h | 64 | ||||
-rw-r--r-- | src/atomic_ops/sysdeps/gcc/generic-arithm.template | 4 | ||||
-rw-r--r-- | src/atomic_ops/sysdeps/gcc/riscv.h | 22 |
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 |