Skip to content

Commit

Permalink
Provide char/short-width CAS for RISC-V w/o -latomic if gcc v14+
Browse files Browse the repository at this point in the history
gcc/riscv (as of v14.0) does not require the client to add -latomic
flag any more if char- or short-width compare-and-swap or an arithmetic
primitive is used.

* src/atomic_ops/sysdeps/gcc/riscv.h [!__clang__
&& !AO_PREFER_BUILTIN_ATOMICS] (AO_NO_char_ARITHM, AO_NO_short_ARITHM):
Do not define if AO_GNUC_PREREQ(14,0).
  • Loading branch information
ivmai committed Oct 7, 2024
1 parent e529da5 commit 3f1ef04
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/atomic_ops/sysdeps/gcc/riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@
# error This file should not be included directly.
#endif

#if defined(__clang__) || defined(AO_PREFER_BUILTIN_ATOMICS)
#if defined(__clang__) || AO_GNUC_PREREQ(14, 0) \
|| defined(AO_PREFER_BUILTIN_ATOMICS)
/* The operations are lock-free even for the types smaller than word. */
# if !(AO_GNUC_PREREQ(13, 0) || AO_CLANG_PREREQ(16, 0))
/* __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros were missing. */
# define AO_GCC_FORCE_HAVE_CAS
# endif
#else

/* As of gcc-7.5, CAS and arithmetic atomic operations for char and */
/* short are supported by the compiler but require -latomic flag. */
/* For older versions of gcc (e.g. 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__ */
#endif

#if defined(__riscv_zacas) && !defined(AO_NO_DOUBLE_CAS) \
&& __SIZEOF_SIZE_T__ == 8
Expand Down

0 comments on commit 3f1ef04

Please sign in to comment.