Skip to content

Commit 7286aae

Browse files
committed
configury: Better support of _Float16
The commit 9e2d9bd (#8844) disabled use of `_Float16` if a compiler (gcc) emits a warning for `_Float16` when compiling with `-pedantic`. This commits reenables `_Float16` using the `__extension__` keyword. Also, move a `AC_MSG_CHECKING` line to an appropriate place and add a comment. Signed-off-by: KAWASHIMA Takahiro <t-kawashima@fujitsu.com>
1 parent 393d086 commit 7286aae

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

config/opal_check_alt_short_float.m4

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dnl -*- shell-script -*-
22
dnl
3-
dnl Copyright (c) 2018-2020 FUJITSU LIMITED. All rights reserved.
3+
dnl Copyright (c) 2018-2021 FUJITSU LIMITED. All rights reserved.
44
dnl Copyright (c) 2020 Cisco Systems, Inc. All rights reserved.
55
dnl $COPYRIGHT$
66
dnl
@@ -47,9 +47,9 @@ AC_DEFUN([OPAL_CHECK_ALT_SHORT_FLOAT], [
4747
# automagically add that flag -- we'll just emit a warning and
4848
# point the user to a README where more information is
4949
# available.
50-
AC_MSG_CHECKING([if compiler supports arithmetic operations on $opal_short_float_type])
5150
AS_IF([test $opal_alt_short_float_exists -eq 1],
52-
[AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
51+
[AC_MSG_CHECKING([if compiler supports arithmetic operations on $opal_short_float_type])
52+
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
5353
static $opal_short_float_type a = 2.5, b = 3.8;
5454
a += b;]])],
5555
[AC_MSG_RESULT([yes])
@@ -74,6 +74,29 @@ a += b;]])],
7474
AC_CHECK_SIZEOF(opal_short_float_t)
7575
AC_CHECK_SIZEOF(opal_short_float_complex_t)
7676
OPAL_C_GET_ALIGNMENT(opal_short_float_t, OPAL_ALIGNMENT_OPAL_SHORT_FLOAT_T)
77+
78+
# Some versions of GCC (around 9.1.0?) emit a warning for _Float16
79+
# when compiling with -pedantic. Using __extension__ can suppress
80+
# the warning. The warning can be detected by -Werror in configure.
81+
# See https://github.com/open-mpi/ompi/issues/8840
82+
AC_MSG_CHECKING([if $opal_short_float_type needs __extension__ keyword])
83+
opal_alt_short_float_needs_extension=0
84+
OPAL_VAR_SCOPE_PUSH([CFLAGS_save])
85+
CFLAGS_save=$CFLAGS
86+
CFLAGS="-Werror $CFLAGS"
87+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([$opal_short_float_type a;])],
88+
[AC_MSG_RESULT([no])],
89+
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([__extension__ $opal_short_float_type a;])],
90+
[opal_alt_short_float_needs_extension=1
91+
AC_MSG_RESULT([yes])],
92+
[AC_MSG_RESULT([no])])])
93+
CFLAGS=$CFLAGS_save
94+
OPAL_VAR_SCOPE_POP
95+
AC_DEFINE_UNQUOTED(OPAL_SHORT_FLOAT_TYPE, [[$opal_short_float_type]],
96+
[User-selected alternate C type of short float (used to redefine opal_short_float_t in opal_bottom.h)])
97+
AC_DEFINE_UNQUOTED(OPAL_SHORT_FLOAT_NEEDS_EXTENSION,
98+
[$opal_alt_short_float_needs_extension],
99+
[Whether $opal_short_float_type needs __extension__ keyword])
77100
elif test "$enable_alt_short_float" != ""; then
78101
AC_MSG_ERROR([Alternate C type of short float $opal_short_float_type requested but not available. Aborting])
79102
fi

opal/include/opal_config_bottom.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* Copyright (c) 2015-2017 Research Organization for Information Science
1717
* and Technology (RIST). All rights reserved.
1818
* Copyright (c) 2015-2017 Intel, Inc. All rights reserved.
19+
* Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
1920
* $COPYRIGHT$
2021
*
2122
* Additional copyrights may follow
@@ -535,6 +536,26 @@ static inline uint16_t ntohs(uint16_t netvar)
535536
# define restrict
536537
# endif
537538

539+
/* We need to define the opal_short_float_t macro in the configure script
540+
because we use it in some other places of the configure script. However
541+
we cannot define it as a macro like "__extension__ [TYPENAME]" because
542+
the __extension__ keyword can only be attached to a C expression. As a
543+
workaround, we once define opal_short_float_t as a macro without
544+
__extension__ in configure and redefine it using typedef here. */
545+
# ifdef HAVE_OPAL_SHORT_FLOAT_T
546+
# undef opal_short_float_t
547+
# if OPAL_SHORT_FLOAT_NEEDS_EXTENSION
548+
__extension__ typedef OPAL_SHORT_FLOAT_TYPE opal_short_float_t;
549+
# else
550+
typedef OPAL_SHORT_FLOAT_TYPE opal_short_float_t;
551+
# endif
552+
# endif
553+
554+
/* We need to define the opal_short_float_complex_t macro in the configure
555+
script because we use it in some other places of the configure script.
556+
However we cannot define it as a macro like "struct { ... }" in configure.
557+
As a workaround, we once define opal_short_float_complex_t as an array
558+
in configure and redefine it as a structure using typedef here. */
538559
# ifdef HAVE_OPAL_SHORT_FLOAT_COMPLEX_T
539560
# undef opal_short_float_complex_t
540561
typedef struct {

0 commit comments

Comments
 (0)