From: Bruno Haible Date: Tue, 11 Aug 2020 17:11:41 +0000 (+0200) Subject: asyncsafe-spin: Use GCC built-ins also on clang. X-Git-Tag: v1.0~3784 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=d4ce9ee2e0eb60490b07abec8ab7af926c783982;p=gnulib.git asyncsafe-spin: Use GCC built-ins also on clang. * lib/asyncsafe-spin.c (asyncsafe_spin_init, do_lock, do_unlock): Use the newer GCC built-ins also on clang. --- diff --git a/ChangeLog b/ChangeLog index 460e6f1663..84549c84bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2020-08-11 Bruno Haible + + asyncsafe-spin: Use GCC built-ins also on clang. + * lib/asyncsafe-spin.c (asyncsafe_spin_init, do_lock, do_unlock): Use + the newer GCC built-ins also on clang. + 2020-08-11 Bruno Haible Use expression statements also on clang. diff --git a/lib/asyncsafe-spin.c b/lib/asyncsafe-spin.c index 6ea5781b36..98d4fadb31 100644 --- a/lib/asyncsafe-spin.c +++ b/lib/asyncsafe-spin.c @@ -67,9 +67,11 @@ asyncsafe_spin_destroy (asyncsafe_spinlock_t *lock) We don't use the C11 (available in GCC >= 4.9) because it would require to link with -latomic. */ -# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined __ibmxl__ -/* Use GCC built-ins (available in GCC >= 4.7) that operate on the first byte of - the lock. +# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) \ + || __clang_major > 3 || (__clang_major__ == 3 && __clang_minor__ >= 1)) \ + && !defined __ibmxl__ +/* Use GCC built-ins (available in GCC >= 4.7 and clang >= 3.1) that operate on + the first byte of the lock. Documentation: */ @@ -129,8 +131,10 @@ do_unlock (asyncsafe_spinlock_t *lock) # endif -# elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) && !defined __ibmxl__ -/* Use GCC built-ins (available in GCC >= 4.1). +# elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) \ + || __clang_major__ >= 3) \ + && !defined __ibmxl__ +/* Use GCC built-ins (available in GCC >= 4.1 and clang >= 3.0). Documentation: */ @@ -184,16 +188,17 @@ do_unlock (asyncsafe_spinlock_t *lock) abort (); } -# elif (defined __GNUC__ || defined __SUNPRO_C) && (defined __sparc || defined __i386 || defined __x86_64__) -/* For older versions of GCC, use inline assembly. - GCC and the Oracle Studio C 12 compiler understand GCC's extended asm syntax, - but the plain Oracle Studio C 11 compiler understands only simple asm. */ +# elif (defined __GNUC__ || defined __clang__ || defined __SUNPRO_C) && (defined __sparc || defined __i386 || defined __x86_64__) +/* For older versions of GCC or clang, use inline assembly. + GCC, clang, and the Oracle Studio C 12 compiler understand GCC's extended + asm syntax, but the plain Oracle Studio C 11 compiler understands only + simple asm. */ /* An implementation that verifies the unlocks. */ static void memory_barrier (void) { -# if defined __GNUC__ || __SUNPRO_C >= 0x590 +# if defined __GNUC__ || defined __clang__ || __SUNPRO_C >= 0x590 # if defined __i386 || defined __x86_64__ asm volatile ("mfence"); # endif @@ -216,7 +221,7 @@ static unsigned int atomic_compare_and_swap (volatile unsigned int *vp, unsigned int cmp, unsigned int newval) { -# if defined __GNUC__ || __SUNPRO_C >= 0x590 +# if defined __GNUC__ || defined __clang__ || __SUNPRO_C >= 0x590 unsigned int oldval; # if defined __i386 || defined __x86_64__ asm volatile (" lock\n cmpxchgl %3,(%1)"