* 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
This commit is contained in:
Ingo Weinhold 2010-01-11 21:38:07 +00:00
parent 1a837b3910
commit 4f7b2c67b0
2 changed files with 31 additions and 0 deletions

View File

@ -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 ;
}
}

View File

@ -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 */