Always fall back to the locked version of atomic_fetch_nand when the
__c11_atomic_fetch_nand builtin isn't available (LLVM prior to 14).
Details
Details
- Reviewers
emaste dim jrtc27 arichardson
Diff Detail
Diff Detail
- Repository
- rS FreeBSD src repository - subversion
- Lint
No Lint Coverage - Unit
No Test Coverage - Build Status
Buildable 45710 Build 42598: arc lint + arc unit
Event Timeline
Comment Actions
This seems a bit problematic in that the set of available symbols depends on the compiler building the tree. It may be that we want to generate them and emit the function without the if (lockfree(ptr) path instead.
Comment Actions
Adding downstream patches is not great but I think in this case it's reasonable. Although maybe upstream would be happy with this too, I'm not sure what the supported compilers for compiler-rt are.
Comment Actions
An alternative version also compiles:
diff --git a/contrib/llvm-project/compiler-rt/lib/builtins/atomic.c b/contrib/llvm-project/compiler-rt/lib/builtins/atomic.c index b8c7f4b0511c..333429751f24 100644 --- a/contrib/llvm-project/compiler-rt/lib/builtins/atomic.c +++ b/contrib/llvm-project/compiler-rt/lib/builtins/atomic.c @@ -336,6 +336,7 @@ OPTIMISED_CASES return tmp; \ } +#if __has_builtin(__c11_atomic_fetch_nand) #define ATOMIC_RMW_NAND(n, lockfree, type) \ type __atomic_fetch_nand_##n(type *ptr, type val, int model) { \ if (lockfree(ptr)) \ @@ -347,6 +348,17 @@ OPTIMISED_CASES unlock(l); \ return tmp; \ } +#else +#define ATOMIC_RMW_NAND(n, lockfree, type) \ + type __atomic_fetch_nand_##n(type *ptr, type val, int model) { \ + Lock *l = lock_for_pointer(ptr); \ + lock(l); \ + type tmp = *ptr; \ + *ptr = ~(tmp & val); \ + unlock(l); \ + return tmp; \ + } +#endif #define OPTIMISED_CASE(n, lockfree, type) ATOMIC_RMW(n, lockfree, type, add, +) OPTIMISED_CASES
Comment Actions
Seems OK to me. I was wondering about trying to reuse the lock version body in the other but I guess the duplication is actually clearer/more maintainable.
Comment Actions
Upstream accepted the first version of this patch as https://reviews.llvm.org/D126710