From 3aa5c524e6202e91290c7be9b4d2b5897232bec4 Mon Sep 17 00:00:00 2001 From: ericwa Date: Sat, 28 May 2011 18:05:14 +0000 Subject: [PATCH] tweak and re-enable atomic ops detection git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@33179 72102866-910b-0410-8b05-ffd578937521 --- Source/NSObject.m | 8 ---- configure.ac | 94 +++++++++++++++++++++++++---------------------- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/Source/NSObject.m b/Source/NSObject.m index 265175567..85d350419 100644 --- a/Source/NSObject.m +++ b/Source/NSObject.m @@ -194,14 +194,6 @@ static void GSLogZombie(id o, SEL sel) #undef GSATOMICREAD #endif -/* - * FIXME: Refrain from using atomic builtins until we know how to reliably check - * whether they do work with GCC. - */ -#ifdef USE_ATOMIC_BUILTINS -#undef USE_ATOMIC_BUILTINS -#endif - #if defined(__MINGW__) #ifndef _WIN64 diff --git a/configure.ac b/configure.ac index 25f48ab1f..a2c4a9fff 100644 --- a/configure.ac +++ b/configure.ac @@ -1013,7 +1013,7 @@ AC_USE_SYSTEM_EXTENSIONS AC_LANG_PUSH(C) AC_MSG_CHECKING([whether the compiler supports atomic operations]); - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[typedef int atomic;]], + AC_LINK_IFELSE([AC_LANG_PROGRAM([[typedef int atomic;]], [[atomic x; atomic y; __sync_bool_compare_and_swap(&x, y, y + 1);]])], have_atomic=yes, have_atomic=no); @@ -1023,51 +1023,59 @@ AC_MSG_CHECKING([whether the compiler supports atomic operations]); [Define if the compiler provides builtins for atomic operations]) else AC_MSG_RESULT([no]); - fi -if test "$CC" = "gcc"; then - saved_CFLAGS="$CFLAGS"; - ATOMIC_CFLAGS=""; + if test "$CC" = "gcc"; then + saved_CFLAGS="$CFLAGS"; + ATOMIC_CFLAGS=""; - # FIXME: Forcing -march=i568 for any i568 or later CPU is a stop gap measure - # to make the compiler emit native assembly for atomic operations on i586 or - # latter processors (GCC by defaults emits code compatible with the original - # i386 and requires library functions to emulate atomic operations). When - # gnustep-make takes care of this kind of target setting, the check can safely - # be removed. - case "$target_cpu" in - i586*|i686*|i786*) - ATOMIC_CFLAGS="-march=i586"; - CFLAGS="$saved_CFLAGS $ATOMIC_CFLAGS"; - OBJCFLAGS="$OBJCFLAGS $ATOMIC_CFLAGS"; - esac - AC_MSG_CHECKING([checking whether atomic operations require an external library]); - AC_LINK_IFELSE([AC_LANG_PROGRAM([[typedef int atomic;]], - [[atomic x; atomic y; __sync_bool_compare_and_swap(&x, y, y + 1);]])], - need_linkage=no, - need_linkage=yes); + # FIXME: Forcing -march=i568 for any i568 or later CPU is a stop gap measure + # to make the compiler emit native assembly for atomic operations on i586 or + # latter processors (GCC by defaults emits code compatible with the original + # i386 and requires library functions to emulate atomic operations). When + # gnustep-make takes care of this kind of target setting, the check can safely + # be removed. + case "$target_cpu" in + i586*|i686*|i786*) + ATOMIC_CFLAGS="-march=i586" + CFLAGS="$saved_CFLAGS $ATOMIC_CFLAGS" + OBJCFLAGS="$OBJCFLAGS $ATOMIC_CFLAGS" + ;; + x86_64) + ATOMIC_CFLAGS="-march=x86-64" + CFLAGS="$saved_CFLAGS $ATOMIC_CFLAGS" + OBJCFLAGS="$OBJCFLAGS $ATOMIC_CFLAGS" + ;; + esac + AC_MSG_CHECKING([whether gcc supports atomic operations by setting -march]); + AC_LINK_IFELSE([AC_LANG_PROGRAM([[typedef int atomic;]], + [[atomic x; atomic y; __sync_bool_compare_and_swap(&x, y, y + 1);]])], + need_march=yes, + need_march=no); - if test "$need_linkage" = "no"; then - AC_MSG_RESULT([no]); - else - AC_MSG_RESULT([yes]); - saved_LDFLAGS="$LDFLAGS"; - LDFLAGS="$saved_LDFLAGS -lgcc"; - AC_MSG_CHECKING([checking for atomic operations from libgcc]); - AC_LINK_IFELSE([AC_LANG_PROGRAM([[typedef int atomic;]], - [[atomic x; atomic y; __sync_bool_compare_and_swap(&x, y, y + 1);]])], - atomic_in_libgcc=yes, - atomic_in_libgcc=no); - if test "$atomic_in_libgcc" = "yes"; then - AC_MSG_RESULT([yes]); - LIBS="$LIBS -lgcc"; - AC_DEFINE(USE_ATOMIC_BUILTINS,1, - [Define if the compiler provides builtins for atomic operations]) - else - LDFLAGS="$saved_LDFLAGS"; - AC_MSG_RESULT([no]); + if test "$need_march" = "yes"; then + AC_MSG_RESULT([yes]); + AC_DEFINE(USE_ATOMIC_BUILTINS,1, + [Define if the compiler provides builtins for atomic operations]) + else + AC_MSG_RESULT([no]); + saved_LDFLAGS="$LDFLAGS"; + LDFLAGS="$saved_LDFLAGS -lgcc"; + AC_MSG_CHECKING([whether gcc supports atomic operations by linikng to libgcc]); + AC_LINK_IFELSE([AC_LANG_PROGRAM([[typedef int atomic;]], + [[atomic x; atomic y; __sync_bool_compare_and_swap(&x, y, y + 1);]])], + atomic_in_libgcc=yes, + atomic_in_libgcc=no); + if test "$atomic_in_libgcc" = "yes"; then + AC_MSG_RESULT([yes]); + LIBS="$LIBS -lgcc"; + AC_DEFINE(USE_ATOMIC_BUILTINS,1, + [Define if the compiler provides builtins for atomic operations]) + else + LDFLAGS="$saved_LDFLAGS"; + AC_MSG_RESULT([no]); + fi + fi fi - fi -fi + fi AC_LANG_POP(C)