Skip to content

Commit bd47b68

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 bd47b68

File tree

1 file changed

+51
-43
lines changed

1 file changed

+51
-43
lines changed

config/opal_config_asm.m4

+51-43
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,39 @@ 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+
[$3
200+
AC_MSG_RESULT([cannot test -- assume yes (cross compiling)])])],
201+
[$4
202+
AC_MSG_RESULT([no])])
203+
])
204+
205+
dnl
206+
dnl Check to see if a specific function is usable.
207+
dnl
208+
dnl Check compilation and actually try ro run the test code
209+
dnl (if we're not cross-compiling) in order to verify that
210+
dnl it actually gives us the correct result:
184211
dnl 1. No compiler/linker flags.
185-
dnl 2. CFLAGS += -mcx16
212+
dnl 2. CFLAGS += -mcx16 (unless --disable-cx16-atomics is used)
186213
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.
190214
dnl
191215
dnl Note that we unfortunately can't use AC SEARCH_LIBS because its
192216
dnl check incorrectly fails (because these functions are special compiler
@@ -213,47 +237,27 @@ AC_DEFUN([OPAL_ASM_CHECK_ATOMIC_FUNC],[
213237
214238
dnl Check with no compiler/linker flags
215239
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-
240+
_OPAL_ASM_CHECK_ATOMIC_FUNC([$1], [$2], [opal_asm_check_func_happy=1], [opal_asm_check_func_happy=0])
222241
dnl If that didn't work, try again with CFLAGS+=mcx16
223242
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-
])
243+
[AC_MSG_CHECKING([for $1 with -mcx16])
244+
AS_IF([test "$enable_cx16_atomics" = "no"],
245+
[AC_MSG_RESULT([skipped])],
246+
[CFLAGS="$CFLAGS -mcx16"
247+
_OPAL_ASM_CHECK_ATOMIC_FUNC([$1], [$2],
248+
[opal_asm_check_func_happy=1],
249+
[opal_asm_check_func_happy=0
250+
CFLAGS=$opal_asm_check_func_CFLAGS_save])])
251+
])
233252
234253
dnl If that didn't work, try again with LIBS+=-latomic
235254
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-
])
255+
[AC_MSG_CHECKING([for $1 with -latomic])
256+
LIBS="$LIBS -latomic"
257+
_OPAL_ASM_CHECK_ATOMIC_FUNC([$1], [$2],
258+
[opal_asm_check_func_happy=1],
259+
[opal_asm_check_func_happy=0
260+
LIBS=$opal_asm_check_func_LIBS_save])])
257261
258262
dnl If we were unsuccessful, restore CFLAGS/LIBS
259263
AS_IF([test $opal_asm_check_func_happy -eq 0],
@@ -1049,6 +1053,10 @@ AC_DEFUN([OPAL_CONFIG_ASM],[
10491053
[AS_HELP_STRING([--enable-builtin-atomics],
10501054
[Enable use of GCC built-in atomics (default: autodetect)])])
10511055
1056+
AC_ARG_ENABLE([cx16-atomics],
1057+
[AS_HELP_STRING([--enable-cx16-atomics],
1058+
[Try using -mcx16 flag if needed (default: autodetect)])])
1059+
10521060
OPAL_CHECK_C11_CSWAP_INT128
10531061
opal_cv_asm_builtin="BUILTIN_NO"
10541062
OPAL_CHECK_GCC_ATOMIC_BUILTINS

0 commit comments

Comments
 (0)