From 4f7b2c67b0b92af7644c62775430133a2a969631 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 11 Jan 2010 21:38:07 +0000 Subject: [PATCH] * gcc 4 features built-ins for atomic operations. If the macro B_USE_BUILTIN_ATOMIC_FUNCTIONS is defined most atomic_*() functions are redefined as macros using the built-ins directly. * Enabled that feature for the x86 build. Might work on other platforms as well, but that needs to be tested. No significant speedup for the -j8 Haiku image build. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35018 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- build/jam/BuildSetup | 5 +++++ headers/os/support/SupportDefs.h | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/build/jam/BuildSetup b/build/jam/BuildSetup index 26ab034e5b..1ae74884f3 100644 --- a/build/jam/BuildSetup +++ b/build/jam/BuildSetup @@ -328,6 +328,11 @@ switch $(HAIKU_ARCH) { HAIKU_C++FLAGS += -march=pentium ; HAIKU_KERNEL_CCFLAGS += -march=pentium ; HAIKU_KERNEL_C++FLAGS += -march=pentium ; + + # Enable use of the gcc built-in atomic functions instead of atomic_*(). + # The former are inlined and have thus less overhead. They are not + # available with gcc 2, but the header will take care of that. + HAIKU_DEFINES += B_USE_BUILTIN_ATOMIC_FUNCTIONS ; } } diff --git a/headers/os/support/SupportDefs.h b/headers/os/support/SupportDefs.h index 4aa4248f59..8d97b15eb9 100644 --- a/headers/os/support/SupportDefs.h +++ b/headers/os/support/SupportDefs.h @@ -199,4 +199,30 @@ extern void* get_stack_frame(void); # define TRUE 1 #endif + +/* Use the built-in atomic functions, if requested and available. */ + +#if defined(B_USE_BUILTIN_ATOMIC_FUNCTIONS) && __GNUC__ >= 4 + +#define atomic_test_and_set(valuePointer, newValue, testAgainst) \ + __sync_val_compare_and_swap(valuePointer, testAgainst, newValue) +#define atomic_add(valuePointer, addValue) \ + __sync_fetch_and_add(valuePointer, addValue) +#define atomic_and(valuePointer, andValue) \ + __sync_fetch_and_and(valuePointer, andValue) +#define atomic_or(valuePointer, orValue) \ + __sync_fetch_and_or(valuePointer, orValue) +#define atomic_get(valuePointer) \ + __sync_fetch_and_or(valuePointer, 0) + // No equivalent to atomic_get(). We simulate it via atomic or. On most + // (all?) 32+ bit architectures aligned 32 bit reads will be atomic anyway, + // though. + +// Note: No equivalent for atomic_set(). It could be simulated by a +// get + atomic test and set loop, but calling the atomic_set() implementation +// might be faster. + +#endif // B_USE_BUILTIN_ATOMIC_FUNCTIONS && __GNUC__ >= 4 + + #endif /* _SUPPORT_DEFS_H */