1
1

asm: remove support for __sync built-in atomics

This commit removes the unsupported __sync built-in atomics in
favor of the GCC built-ins. The priority order (if not modified
by configure flags) is: C11, custom atomics
(opal/include/opal/sys/*), then GCC built-ins.

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
Этот коммит содержится в:
Nathan Hjelm 2020-02-26 06:30:34 -08:00
родитель 547d6c4380
Коммит 038dcad8b5
5 изменённых файлов: 72 добавлений и 297 удалений

Просмотреть файл

@ -285,37 +285,6 @@ AC_DEFUN([OPAL_CHECK_SYNC_BUILTIN_CSWAP_INT128], [
OPAL_VAR_SCOPE_POP
])
AC_DEFUN([OPAL_CHECK_SYNC_BUILTINS], [
AC_MSG_CHECKING([for __sync builtin atomics])
AC_TRY_LINK([long tmp;], [__sync_synchronize();
__sync_bool_compare_and_swap(&tmp, 0, 1);
__sync_add_and_fetch(&tmp, 1);],
[AC_MSG_RESULT([yes])
$1],
[AC_MSG_RESULT([no])
$2])
AC_MSG_CHECKING([for 64-bit __sync builtin atomics])
AC_TRY_LINK([
#include <stdint.h>
uint64_t tmp;], [
__sync_bool_compare_and_swap(&tmp, 0, 1);
__sync_add_and_fetch(&tmp, 1);],
[AC_MSG_RESULT([yes])
opal_asm_sync_have_64bit=1],
[AC_MSG_RESULT([no])
opal_asm_sync_have_64bit=0])
AC_DEFINE_UNQUOTED([OPAL_ASM_SYNC_HAVE_64BIT],[$opal_asm_sync_have_64bit],
[Whether 64-bit is supported by the __sync builtin atomics])
# Check for 128-bit support
OPAL_CHECK_SYNC_BUILTIN_CSWAP_INT128
])
AC_DEFUN([OPAL_CHECK_GCC_BUILTIN_CSWAP_INT128], [
OPAL_VAR_SCOPE_PUSH([atomic_compare_exchange_n_128_result atomic_compare_exchange_n_128_CFLAGS_save atomic_compare_exchange_n_128_LIBS_save])
@ -361,9 +330,10 @@ AC_DEFUN([OPAL_CHECK_GCC_BUILTIN_CSWAP_INT128], [
])
AC_DEFUN([OPAL_CHECK_GCC_ATOMIC_BUILTINS], [
AC_MSG_CHECKING([for __atomic builtin atomics])
if test -z "$opal_cv_have___atomic" ; then
AC_MSG_CHECKING([for 32-bit GCC built-in atomics])
AC_TRY_LINK([
AC_TRY_LINK([
#include <stdint.h>
uint32_t tmp, old = 0;
uint64_t tmp64, old64 = 0;], [
@ -372,13 +342,39 @@ __atomic_compare_exchange_n(&tmp, &old, 1, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED
__atomic_add_fetch(&tmp, 1, __ATOMIC_RELAXED);
__atomic_compare_exchange_n(&tmp64, &old64, 1, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
__atomic_add_fetch(&tmp64, 1, __ATOMIC_RELAXED);],
[AC_MSG_RESULT([yes])
$1],
[AC_MSG_RESULT([no])
$2])
[opal_cv_have___atomic=yes],
[opal_cv_have___atomic=no])
# Check for 128-bit support
OPAL_CHECK_GCC_BUILTIN_CSWAP_INT128
AC_MSG_RESULT([$opal_cv_have___atomic])
if test $opal_cv_have___atomic = "yes" ; then
AC_MSG_CHECKING([for 64-bit GCC built-in atomics])
AC_TRY_LINK([
#include <stdint.h>
uint64_t tmp64, old64 = 0;], [
__atomic_compare_exchange_n(&tmp64, &old64, 1, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
__atomic_add_fetch(&tmp64, 1, __ATOMIC_RELAXED);],
[opal_cv_have___atomic_64=yes],
[opal_cv_have___atomic_64=no])
AC_MSG_RESULT([$opal_cv_have___atomic_64])
if test $opal_cv_have___atomic_64 = "yes" ; then
AC_MSG_CHECKING([if 64-bit GCC built-in atomics are lock-free])
AC_RUN_IFELSE([AC_LANG_PROGRAM([], [if (!__atomic_is_lock_free (8, 0)) { return 1; }])],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])
opal_cv_have___atomic_64=no],
[AC_MSG_RESULT([cannot test -- assume yes (cross compiling)])])
fi
else
opal_cv_have___atomic_64=no
fi
# Check for 128-bit support
OPAL_CHECK_GCC_BUILTIN_CSWAP_INT128
fi
])
AC_DEFUN([OPAL_CHECK_C11_CSWAP_INT128], [
@ -425,28 +421,6 @@ AC_DEFUN([OPAL_CHECK_C11_CSWAP_INT128], [
OPAL_VAR_SCOPE_POP
])
AC_DEFUN([OPAL_CHECK_GCC_ATOMIC_BUILTINS], [
AC_MSG_CHECKING([for __atomic builtin atomics])
AC_TRY_LINK([
#include <stdint.h>
uint32_t tmp, old = 0;
uint64_t tmp64, old64 = 0;], [
__atomic_thread_fence(__ATOMIC_SEQ_CST);
__atomic_compare_exchange_n(&tmp, &old, 1, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
__atomic_add_fetch(&tmp, 1, __ATOMIC_RELAXED);
__atomic_compare_exchange_n(&tmp64, &old64, 1, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
__atomic_add_fetch(&tmp64, 1, __ATOMIC_RELAXED);],
[AC_MSG_RESULT([yes])
$1],
[AC_MSG_RESULT([no])
$2])
# Check for 128-bit support
OPAL_CHECK_GCC_BUILTIN_CSWAP_INT128
])
dnl #################################################################
dnl
dnl OPAL_CHECK_ASM_TEXT
@ -1142,9 +1116,11 @@ AC_DEFUN([OPAL_CONFIG_ASM],[
AC_ARG_ENABLE([builtin-atomics],
[AC_HELP_STRING([--enable-builtin-atomics],
[Enable use of __sync builtin atomics (default: disabled)])])
[Enable use of GCC built-in atomics (default: autodetect)])])
OPAL_CHECK_C11_CSWAP_INT128
opal_cv_asm_builtin="BUILTIN_NO"
OPAL_CHECK_GCC_ATOMIC_BUILTINS
if test "x$enable_c11_atomics" != "xno" && test "$opal_cv_c11_supported" = "yes" ; then
opal_cv_asm_builtin="BUILTIN_C11"
@ -1152,14 +1128,13 @@ AC_DEFUN([OPAL_CONFIG_ASM],[
elif test "x$enable_c11_atomics" = "xyes"; then
AC_MSG_WARN([C11 atomics were requested but are not supported])
AC_MSG_ERROR([Cannot continue])
else
opal_cv_asm_builtin="BUILTIN_NO"
AS_IF([test "$opal_cv_asm_builtin" = "BUILTIN_NO" && test "$enable_builtin_atomics" = "yes"],
[OPAL_CHECK_GCC_ATOMIC_BUILTINS([opal_cv_asm_builtin="BUILTIN_GCC"], [])])
AS_IF([test "$opal_cv_asm_builtin" = "BUILTIN_NO" && test "$enable_builtin_atomics" = "yes"],
[OPAL_CHECK_SYNC_BUILTINS([opal_cv_asm_builtin="BUILTIN_SYNC"], [])])
AS_IF([test "$opal_cv_asm_builtin" = "BUILTIN_NO" && test "$enable_builtin_atomics" = "yes"],
[AC_MSG_ERROR([__sync builtin atomics requested but not found.])])
elif test "$enable_builtin_atomics" = "yes" ; then
if test $opal_cv_have___atomic = "yes" ; then
opal_cv_asm_builtin="BUILTIN_GCC"
else
AC_MSG_WARN([GCC built-in atomics requested but not found.])
AC_MSG_ERROR([Cannot continue])
fi
fi
OPAL_CHECK_ASM_PROC
@ -1176,7 +1151,12 @@ AC_DEFUN([OPAL_CONFIG_ASM],[
# find our architecture for purposes of assembly stuff
opal_cv_asm_arch="UNSUPPORTED"
OPAL_GCC_INLINE_ASSIGN=""
OPAL_ASM_SUPPORT_64BIT=0
if test "$opal_cv_have___atomic_64" ; then
OPAL_ASM_SUPPORT_64BIT=1
else
OPAL_ASM_SUPPORT_64BIT=0
fi
case "${host}" in
x86_64-*x32)
opal_cv_asm_arch="X86_64"
@ -1198,8 +1178,6 @@ AC_DEFUN([OPAL_CONFIG_ASM],[
opal_cv_asm_arch="ARM64"
OPAL_ASM_SUPPORT_64BIT=1
OPAL_ASM_ARM_VERSION=8
AC_DEFINE_UNQUOTED([OPAL_ASM_ARM_VERSION], [$OPAL_ASM_ARM_VERSION],
[What ARM assembly version to use])
OPAL_GCC_INLINE_ASSIGN='"mov %0, #0" : "=&r"(ret)'
;;
@ -1207,8 +1185,6 @@ AC_DEFUN([OPAL_CONFIG_ASM],[
opal_cv_asm_arch="ARM"
OPAL_ASM_SUPPORT_64BIT=1
OPAL_ASM_ARM_VERSION=7
AC_DEFINE_UNQUOTED([OPAL_ASM_ARM_VERSION], [$OPAL_ASM_ARM_VERSION],
[What ARM assembly version to use])
OPAL_GCC_INLINE_ASSIGN='"mov %0, #0" : "=&r"(ret)'
;;
@ -1217,8 +1193,6 @@ AC_DEFUN([OPAL_CONFIG_ASM],[
OPAL_ASM_SUPPORT_64BIT=0
OPAL_ASM_ARM_VERSION=6
CCASFLAGS="$CCASFLAGS -march=armv7-a"
AC_DEFINE_UNQUOTED([OPAL_ASM_ARM_VERSION], [$OPAL_ASM_ARM_VERSION],
[What ARM assembly version to use])
OPAL_GCC_INLINE_ASSIGN='"mov %0, #0" : "=&r"(ret)'
;;
@ -1269,37 +1243,27 @@ AC_MSG_ERROR([Can not continue.])
;;
*)
OPAL_CHECK_SYNC_BUILTINS([opal_cv_asm_builtin="BUILTIN_SYNC"],
[AC_MSG_ERROR([No atomic primitives available for $host])])
;;
if test $opal_cv_have___atomic = "yes" ; then
opal_cv_asm_builtin="BUILTIN_GCC"
else
AC_MSG_ERROR([No atomic primitives available for $host])
fi
;;
esac
if test "x$OPAL_ASM_SUPPORT_64BIT" = "x1" && test "$opal_cv_asm_builtin" = "BUILTIN_SYNC" &&
test "$opal_asm_sync_have_64bit" = "0" ; then
# __sync builtins exist but do not implement 64-bit support. Fall back on inline asm.
opal_cv_asm_builtin="BUILTIN_NO"
fi
if ! test -z "$OPAL_ASM_ARM_VERSION" ; then
AC_DEFINE_UNQUOTED([OPAL_ASM_ARM_VERSION], [$OPAL_ASM_ARM_VERSION],
[What ARM assembly version to use])
fi
if test "$opal_cv_asm_builtin" = "BUILTIN_SYNC" || test "$opal_cv_asm_builtin" = "BUILTIN_GCC" ; then
AC_DEFINE([OPAL_C_GCC_INLINE_ASSEMBLY], [1],
[Whether C compiler supports GCC style inline assembly])
else
AC_DEFINE_UNQUOTED([OPAL_ASM_SUPPORT_64BIT],
[$OPAL_ASM_SUPPORT_64BIT],
[Whether we can do 64bit assembly operations or not. Should not be used outside of the assembly header files])
AC_SUBST([OPAL_ASM_SUPPORT_64BIT])
#
# figure out if we need any special function start / stop code
#
case $host_os in
aix*)
opal_asm_arch_config="aix"
;;
*)
opal_asm_arch_config="default"
;;
esac
if test "$opal_cv_asm_builtin" = "BUILTIN_GCC" ; then
AC_DEFINE([OPAL_C_GCC_INLINE_ASSEMBLY], [1],
[Whether C compiler supports GCC style inline assembly])
else
AC_DEFINE_UNQUOTED([OPAL_ASM_SUPPORT_64BIT],
[$OPAL_ASM_SUPPORT_64BIT],
[Whether we can do 64bit assembly operations or not. Should not be used outside of the assembly header files])
AC_SUBST([OPAL_ASM_SUPPORT_64BIT])
opal_cv_asm_inline_supported="no"
# now that we know our architecture, try to inline assemble
@ -1330,7 +1294,7 @@ AC_MSG_ERROR([Can not continue.])
AC_DEFINE_UNQUOTED([OPAL_ASSEMBLY_FORMAT], ["$OPAL_ASSEMBLY_FORMAT"],
[Format of assembly file])
AC_SUBST([OPAL_ASSEMBLY_FORMAT])
fi # if opal_cv_asm_builtin = BUILTIN_SYNC
fi # if opal_cv_asm_builtin = BUILTIN_GCC
result="OPAL_$opal_cv_asm_arch"
OPAL_ASSEMBLY_ARCH="$opal_cv_asm_arch"
@ -1388,7 +1352,7 @@ AC_DEFUN([OPAL_ASM_FIND_FILE], [
AC_REQUIRE([AC_PROG_GREP])
AC_REQUIRE([AC_PROG_FGREP])
if test "$opal_cv_asm_arch" != "WINDOWS" && test "$opal_cv_asm_builtin" != "BUILTIN_SYNC" && test "$opal_cv_asm_builtin" != "BUILTIN_GCC" && test "$opal_cv_asm_builtin" != "BUILTIN_OSX" && test "$opal_cv_asm_inline_arch" = "no" ; then
if test "$opal_cv_asm_arch" != "WINDOWS" && test "$opal_cv_asm_builtin" != "BUILTIN_GCC" && test "$opal_cv_asm_builtin" != "BUILTIN_OSX" && test "$opal_cv_asm_inline_arch" = "no" ; then
AC_MSG_ERROR([no atomic support available. exiting])
else
# On windows with VC++, atomics are done with compiler primitives

Просмотреть файл

@ -15,6 +15,7 @@
# reserved.
# Copyright (c) 2017 Research Organization for Information Science
# and Technology (RIST). All rights reserved.
# Copyright (c) 2020 Google, LLC. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
@ -38,5 +39,4 @@ include opal/sys/arm64/Makefile.am
include opal/sys/ia32/Makefile.am
include opal/sys/powerpc/Makefile.am
include opal/sys/sparcv9/Makefile.am
include opal/sys/sync_builtin/Makefile.am
include opal/sys/gcc_builtin/Makefile.am

Просмотреть файл

@ -41,7 +41,6 @@
#define OPAL_SPARCV9_64 0062
#define OPAL_ARM 0100
#define OPAL_ARM64 0101
#define OPAL_BUILTIN_SYNC 0200
#define OPAL_BUILTIN_GCC 0202
#define OPAL_BUILTIN_NO 0203
#define OPAL_BUILTIN_C11 0204

Просмотреть файл

@ -1,23 +0,0 @@
#
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The University of Tennessee and The University
# of Tennessee Research Foundation. All rights
# reserved.
# Copyright (c) 2004-2009 High Performance Computing Center Stuttgart,
# University of Stuttgart. All rights reserved.
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# Copyright (c) 2011 Sandia National Laboratories. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
# This makefile.am does not stand on its own - it is included from opal/include/Makefile.am
headers += \
opal/sys/sync_builtin/atomic.h

Просмотреть файл

@ -1,165 +0,0 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2013 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2011 Sandia National Laboratories. All rights reserved.
* Copyright (c) 2014-2018 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2017 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OPAL_SYS_ARCH_ATOMIC_H
#define OPAL_SYS_ARCH_ATOMIC_H 1
/**********************************************************************
*
* Memory Barriers
*
*********************************************************************/
#define OPAL_HAVE_ATOMIC_MEM_BARRIER 1
static inline void opal_atomic_mb(void)
{
__sync_synchronize();
}
static inline void opal_atomic_rmb(void)
{
__sync_synchronize();
}
static inline void opal_atomic_wmb(void)
{
__sync_synchronize();
}
#define MB() opal_atomic_mb()
/**********************************************************************
*
* Atomic math operations
*
*********************************************************************/
#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_32 1
static inline bool opal_atomic_compare_exchange_strong_32 (opal_atomic_int32_t *addr, int32_t *oldval, int32_t newval)
{
int32_t prev = __sync_val_compare_and_swap (addr, *oldval, newval);
bool ret = prev == *oldval;
*oldval = prev;
return ret;
}
#define opal_atomic_compare_exchange_strong_acq_32 opal_atomic_compare_exchange_strong_32
#define opal_atomic_compare_exchange_strong_rel_32 opal_atomic_compare_exchange_strong_32
#define OPAL_HAVE_ATOMIC_MATH_32 1
#define OPAL_HAVE_ATOMIC_ADD_32 1
static inline int32_t opal_atomic_fetch_add_32(opal_atomic_int32_t *addr, int32_t delta)
{
return __sync_fetch_and_add(addr, delta);
}
#define OPAL_HAVE_ATOMIC_AND_32 1
static inline int32_t opal_atomic_fetch_and_32(opal_atomic_int32_t *addr, int32_t value)
{
return __sync_fetch_and_and(addr, value);
}
#define OPAL_HAVE_ATOMIC_OR_32 1
static inline int32_t opal_atomic_fetch_or_32(opal_atomic_int32_t *addr, int32_t value)
{
return __sync_fetch_and_or(addr, value);
}
#define OPAL_HAVE_ATOMIC_XOR_32 1
static inline int32_t opal_atomic_fetch_xor_32(opal_atomic_int32_t *addr, int32_t value)
{
return __sync_fetch_and_xor(addr, value);
}
#define OPAL_HAVE_ATOMIC_SUB_32 1
static inline int32_t opal_atomic_fetch_sub_32(opal_atomic_int32_t *addr, int32_t delta)
{
return __sync_fetch_and_sub(addr, delta);
}
#if OPAL_ASM_SYNC_HAVE_64BIT
#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_64 1
static inline bool opal_atomic_compare_exchange_strong_64 (opal_atomic_int64_t *addr, int64_t *oldval, int64_t newval)
{
int64_t prev = __sync_val_compare_and_swap (addr, *oldval, newval);
bool ret = prev == *oldval;
*oldval = prev;
return ret;
}
#define opal_atomic_compare_exchange_strong_acq_64 opal_atomic_compare_exchange_strong_64
#define opal_atomic_compare_exchange_strong_rel_64 opal_atomic_compare_exchange_strong_64
#define OPAL_HAVE_ATOMIC_MATH_64 1
#define OPAL_HAVE_ATOMIC_ADD_64 1
static inline int64_t opal_atomic_fetch_add_64(opal_atomic_int64_t *addr, int64_t delta)
{
return __sync_fetch_and_add(addr, delta);
}
#define OPAL_HAVE_ATOMIC_AND_64 1
static inline int64_t opal_atomic_fetch_and_64(opal_atomic_int64_t *addr, int64_t value)
{
return __sync_fetch_and_and(addr, value);
}
#define OPAL_HAVE_ATOMIC_OR_64 1
static inline int64_t opal_atomic_fetch_or_64(opal_atomic_int64_t *addr, int64_t value)
{
return __sync_fetch_and_or(addr, value);
}
#define OPAL_HAVE_ATOMIC_XOR_64 1
static inline int64_t opal_atomic_fetch_xor_64(opal_atomic_int64_t *addr, int64_t value)
{
return __sync_fetch_and_xor(addr, value);
}
#define OPAL_HAVE_ATOMIC_SUB_64 1
static inline int64_t opal_atomic_fetch_sub_64(opal_atomic_int64_t *addr, int64_t delta)
{
return __sync_fetch_and_sub(addr, delta);
}
#endif
#if OPAL_HAVE_SYNC_BUILTIN_CSWAP_INT128
static inline bool opal_atomic_compare_exchange_strong_128 (opal_atomic_int128_t *addr,
opal_int128_t *oldval, opal_int128_t newval)
{
opal_int128_t prev = __sync_val_compare_and_swap (addr, *oldval, newval);
bool ret = prev == *oldval;
*oldval = prev;
return ret;
}
#define OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 1
#endif
#endif /* ! OPAL_SYS_ARCH_ATOMIC_H */