Skip to content

Commit fe9605b

Browse files
committed
atomics: add the --disable-cx16-atomics
Do not try the -mcx16 flag if --disable-cx16-atomics is used, and prevent the generation of instructions that are not available on all x86 platforms (such as Celeron N4000). Always try to run a simple test to make sure the selected atomic generate correct results. Thanks Orion Poplawski for reporting this issue. Refs. #9022 Signed-off-by: Gilles Gouaillardet <gilles@rist.or.jp>
1 parent 6236284 commit fe9605b

File tree

1 file changed

+50
-43
lines changed

1 file changed

+50
-43
lines changed

config/opal_config_asm.m4

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dnl Copyright (c) 2004-2005 The Regents of the University of California.
1111
dnl All rights reserved.
1212
dnl Copyright (c) 2008-2018 Cisco Systems, Inc. All rights reserved.
1313
dnl Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
14-
dnl Copyright (c) 2015-2018 Research Organization for Information Science
14+
dnl Copyright (c) 2015-2021 Research Organization for Information Science
1515
dnl and Technology (RIST). All rights reserved.
1616
dnl Copyright (c) 2014-2018 Los Alamos National Security, LLC. All rights
1717
dnl reserved.
@@ -178,15 +178,38 @@ int main(int argc, char** argv)
178178
dnl ------------------------------------------------------------------
179179

180180
dnl
181-
dnl Check to see if a specific function is linkable.
181+
dnl Helper to Check if a specific function is usable.
182182
dnl
183-
dnl Check with:
183+
dnl
184+
dnl $1: function name to print
185+
dnl $2: program to test
186+
dnl $3: action if success
187+
dnl #4: action if fail
188+
dnl
189+
AC_DEFUN([_OPAL_ASM_CHECK_ATOMIC_FUNC],[
190+
AC_LINK_IFELSE([$2],
191+
[AC_MSG_RESULT([yes])
192+
dnl make sure it works
193+
AC_MSG_CHECKING([if $1() gives correct results])
194+
AC_RUN_IFELSE([$2],
195+
[$3
196+
AC_MSG_RESULT([yes])],
197+
[$4
198+
AC_MSG_RESULT([no])],
199+
[AC_MSG_RESULT([cannot test -- assume yes (cross compiling)])])],
200+
[$4
201+
AC_MSG_RESULT([no])])
202+
])
203+
204+
dnl
205+
dnl Check to see if a specific function is usable.
206+
dnl
207+
dnl Check compilation and actually try ro run the test code
208+
dnl (if we're not cross-compiling) in order to verify that
209+
dnl it actually gives us the correct result:
184210
dnl 1. No compiler/linker flags.
185-
dnl 2. CFLAGS += -mcx16
211+
dnl 2. CFLAGS += -mcx16 (unless --disable-cx16-atomics is used)
186212
dnl 3. LIBS += -latomic
187-
dnl 4. Finally, if it links ok with any of #1, #2, or #3, actually try
188-
dnl to run the test code (if we're not cross-compiling) and verify
189-
dnl that it actually gives us the correct result.
190213
dnl
191214
dnl Note that we unfortunately can't use AC SEARCH_LIBS because its
192215
dnl check incorrectly fails (because these functions are special compiler
@@ -213,47 +236,27 @@ AC_DEFUN([OPAL_ASM_CHECK_ATOMIC_FUNC],[
213236
214237
dnl Check with no compiler/linker flags
215238
AC_MSG_CHECKING([for $1])
216-
AC_LINK_IFELSE([$2],
217-
[opal_asm_check_func_happy=1
218-
AC_MSG_RESULT([yes])],
219-
[opal_asm_check_func_happy=0
220-
AC_MSG_RESULT([no])])
221-
239+
_OPAL_ASM_CHECK_ATOMIC_FUNC([$1], [$2], [opal_asm_check_func_happy=1], [opal_asm_check_func_happy=0])
222240
dnl If that didn't work, try again with CFLAGS+=mcx16
223241
AS_IF([test $opal_asm_check_func_happy -eq 0],
224-
[AC_MSG_CHECKING([for $1 with -mcx16])
225-
CFLAGS="$CFLAGS -mcx16"
226-
AC_LINK_IFELSE([$2],
227-
[opal_asm_check_func_happy=1
228-
AC_MSG_RESULT([yes])],
229-
[opal_asm_check_func_happy=0
230-
CFLAGS=$opal_asm_check_func_CFLAGS_save
231-
AC_MSG_RESULT([no])])
232-
])
242+
[AC_MSG_CHECKING([for $1 with -mcx16])
243+
AS_IF([test "$enable_cx16_atomics" = "no"],
244+
[AC_MSG_RESULT([skipped])],
245+
[CFLAGS="$CFLAGS -mcx16"
246+
_OPAL_ASM_CHECK_ATOMIC_FUNC([$1], [$2],
247+
[opal_asm_check_func_happy=1],
248+
[opal_asm_check_func_happy=0
249+
CFLAGS=$opal_asm_check_func_CFLAGS_save])])
250+
])
233251
234252
dnl If that didn't work, try again with LIBS+=-latomic
235253
AS_IF([test $opal_asm_check_func_happy -eq 0],
236-
[AC_MSG_CHECKING([for $1 with -latomic])
237-
LIBS="$LIBS -latomic"
238-
AC_LINK_IFELSE([$2],
239-
[opal_asm_check_func_happy=1
240-
AC_MSG_RESULT([yes])],
241-
[opal_asm_check_func_happy=0
242-
LIBS=$opal_asm_check_func_LIBS_save
243-
AC_MSG_RESULT([no])])
244-
])
245-
246-
dnl If we have it, try it and make sure it gives a correct result.
247-
dnl As of Aug 2018, we know that it links but does *not* work on clang
248-
dnl 6 on ARM64.
249-
AS_IF([test $opal_asm_check_func_happy -eq 1],
250-
[AC_MSG_CHECKING([if $1() gives correct results])
251-
AC_RUN_IFELSE([$2],
252-
[AC_MSG_RESULT([yes])],
253-
[opal_asm_check_func_happy=0
254-
AC_MSG_RESULT([no])],
255-
[AC_MSG_RESULT([cannot test -- assume yes (cross compiling)])])
256-
])
254+
[AC_MSG_CHECKING([for $1 with -latomic])
255+
LIBS="$LIBS -latomic"
256+
_OPAL_ASM_CHECK_ATOMIC_FUNC([$1], [$2],
257+
[opal_asm_check_func_happy=1],
258+
[opal_asm_check_func_happy=0
259+
LIBS=$opal_asm_check_func_LIBS_save])])
257260
258261
dnl If we were unsuccessful, restore CFLAGS/LIBS
259262
AS_IF([test $opal_asm_check_func_happy -eq 0],
@@ -1049,6 +1052,10 @@ AC_DEFUN([OPAL_CONFIG_ASM],[
10491052
[AS_HELP_STRING([--enable-builtin-atomics],
10501053
[Enable use of GCC built-in atomics (default: autodetect)])])
10511054
1055+
AC_ARG_ENABLE([cx16-atomics],
1056+
[AS_HELP_STRING([--enable-cx16-atomics],
1057+
[Try using -mcx16 flag if needed (default: autodetect)])])
1058+
10521059
OPAL_CHECK_C11_CSWAP_INT128
10531060
opal_cv_asm_builtin="BUILTIN_NO"
10541061
OPAL_CHECK_GCC_ATOMIC_BUILTINS

0 commit comments

Comments
 (0)