diff --git a/dist/aclocal/mutex.m4 b/dist/aclocal/mutex.m4 index f414fa736..4db253275 100644 --- a/dist/aclocal/mutex.m4 +++ b/dist/aclocal/mutex.m4 @@ -1010,6 +1010,8 @@ AH_TEMPLATE(HAVE_ATOMIC_SOLARIS, [Define to 1 to use Solaris library routes for atomic operations.]) AH_TEMPLATE(HAVE_ATOMIC_BUILTINS, [Define to 1 to use GCC __atomic_* builtins for atomic operations.]) +AH_TEMPLATE(HAVE_ATOMIC_GCC_BUILTIN, + [Define to 1 when the GCC/Clang __atomic_* builtin tier is selected.]) AH_TEMPLATE(HAVE_SYNC_BUILTINS, [Define to 1 to use GCC __sync_* builtins for atomic operations.]) AH_TEMPLATE(HAVE_ATOMIC_AARCH64, @@ -1029,12 +1031,25 @@ if test "$db_cv_mingw" = yes; then db_cv_atomic=mingw fi +if test "$db_cv_atomic" = no; then +AC_LINK_IFELSE([AC_LANG_PROGRAM([[ +#include ]], [[ + uint32_t val32 = 1; + uint32_t exp32 = 1; + intptr_t valp = 1; + intptr_t expp = 1; + __atomic_add_fetch(&val32, 1, __ATOMIC_SEQ_CST); + __atomic_compare_exchange_n(&val32, &exp32, 2, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); + __atomic_compare_exchange_n(&valp, &expp, 2, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); +]])], [db_cv_atomic="gcc/__atomic"]) +fi + if test "$db_cv_atomic" = no; then AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [[ #if ((defined(i386) || defined(__i386__)) && defined(__GNUC__)) - exit(0); + (void)0; #elif ((defined(x86_64) || defined(__x86_64__)) && defined(__GNUC__)) - exit(0); + (void)0; #else FAIL TO COMPILE/LINK #endif @@ -1053,6 +1068,12 @@ fi ]) case "$db_cv_atomic" in + gcc/__atomic) + AC_DEFINE(HAVE_ATOMIC_SUPPORT) + AC_DEFINE(HAVE_ATOMIC_BUILTINS) + AC_DEFINE(HAVE_ATOMIC_GCC_BUILTIN) + ;; + x86/gcc-assembly) AC_DEFINE(HAVE_ATOMIC_SUPPORT) AC_DEFINE(HAVE_ATOMIC_X86_GCC_ASSEMBLY) @@ -1085,6 +1106,16 @@ fi AC_CACHE_CHECK([for 64-bit atomic operations], db_cv_atomic_64bit, [ db_cv_atomic_64bit=no case "$db_cv_atomic" in + gcc/__atomic) + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ +#include ]], [[ + int64_t val = 1; + int64_t exp = 1; + __atomic_add_fetch(&val, 1, __ATOMIC_SEQ_CST); + __atomic_sub_fetch(&val, 1, __ATOMIC_SEQ_CST); + __atomic_compare_exchange_n(&val, &exp, 2, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); +]])], [db_cv_atomic_64bit=yes]) + ;; x86/gcc-assembly) AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include ]], [[ diff --git a/dist/config.hin b/dist/config.hin index 4a2b1a758..95fbb4c7c 100644 --- a/dist/config.hin +++ b/dist/config.hin @@ -64,6 +64,9 @@ /* Define to 1 to use GCC __atomic_* builtins for atomic operations. */ #undef HAVE_ATOMIC_BUILTINS +/* Define to 1 when the GCC/Clang __atomic_* builtin tier is selected. */ +#undef HAVE_ATOMIC_GCC_BUILTIN + /* Define to 1 to use Solaris library routes for atomic operations. */ #undef HAVE_ATOMIC_SOLARIS diff --git a/dist/configure b/dist/configure index 1af81ff8f..02aeab90f 100755 --- a/dist/configure +++ b/dist/configure @@ -25809,6 +25809,7 @@ esac + { printf '%s\n' "$as_me:${as_lineno-$LINENO}: checking for atomic operations" >&5 printf %s "checking for atomic operations... " >&6; } if test ${db_cv_atomic+y} @@ -25827,6 +25828,35 @@ if test "$db_cv_mingw" = yes; then db_cv_atomic=mingw fi +if test "$db_cv_atomic" = no; then +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +int +main (void) +{ + + uint32_t val32 = 1; + uint32_t exp32 = 1; + intptr_t valp = 1; + intptr_t expp = 1; + __atomic_add_fetch(&val32, 1, __ATOMIC_SEQ_CST); + __atomic_compare_exchange_n(&val32, &exp32, 2, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); + __atomic_compare_exchange_n(&valp, &expp, 2, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + db_cv_atomic="gcc/__atomic" +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext +fi + if test "$db_cv_atomic" = no; then cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -25836,9 +25866,9 @@ main (void) { #if ((defined(i386) || defined(__i386__)) && defined(__GNUC__)) - exit(0); + (void)0; #elif ((defined(x86_64) || defined(__x86_64__)) && defined(__GNUC__)) - exit(0); + (void)0; #else FAIL TO COMPILE/LINK #endif @@ -25886,6 +25916,15 @@ fi printf '%s\n' "$db_cv_atomic" >&6; } case "$db_cv_atomic" in + gcc/__atomic) + printf '%s\n' "#define HAVE_ATOMIC_SUPPORT 1" >>confdefs.h + + printf '%s\n' "#define HAVE_ATOMIC_BUILTINS 1" >>confdefs.h + + printf '%s\n' "#define HAVE_ATOMIC_GCC_BUILTIN 1" >>confdefs.h + + ;; + x86/gcc-assembly) printf '%s\n' "#define HAVE_ATOMIC_SUPPORT 1" >>confdefs.h @@ -25958,6 +25997,32 @@ else case e in #( e) db_cv_atomic_64bit=no case "$db_cv_atomic" in + gcc/__atomic) + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +int +main (void) +{ + + int64_t val = 1; + int64_t exp = 1; + __atomic_add_fetch(&val, 1, __ATOMIC_SEQ_CST); + __atomic_sub_fetch(&val, 1, __ATOMIC_SEQ_CST); + __atomic_compare_exchange_n(&val, &exp, 2, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + db_cv_atomic_64bit=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext + ;; x86/gcc-assembly) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */