diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-04-22 19:17:15 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2020-04-22 21:34:19 +0200 |
commit | 1868599f8daf7798018ce8a8f314015f5a2ac520 (patch) | |
tree | 4a9e4d8e1017d6bc4c3f1de3eaff89af049d9c90 /libgfortran/configure | |
parent | 545f1addf7247a800bbb943650efaa4c35d3bd1d (diff) |
libgfortran: Provide some further math library fallbacks [PR94694]
The following patch provides some further math library fallbacks.
fmaf can be implemented using fma if available, fma and fmal can use
x * y + z as fallback, it is not perfect, but e.g. glibc on various arches
has been using that as fallback for many years,
and copysign/copysignl/fabs/fabsl can be implemented using corresponding
__builtin_* if we make sure that gcc expands it inline instead of using
a library call (these days it is expanded inline on most targets).
2020-04-22 Jakub Jelinek <jakub@redhat.com>
PR libfortran/94694
PR libfortran/94586
* configure.ac: Add math func checks for fmaf, fma and fmal. Add
HAVE_INLINE_BUILTIN_COPYSIGN check.
* c99_protos.h (copysign, fmaf, fma, fmal): Provide fallback
prototypes.
(HAVE_COPYSIGN, HAVE_FMAF, HAVE_FMA, HAVE_FMAL): Define if not
defined and fallback version is provided.
* intrinsics/c99_functions.c (copysign, fmaf, fma, fmal): Provide
fallback implementations if possible
* configure: Regenerated.
* config.h.in: Regenerated.
* math.m4 (GCC_CHECK_MATH_INLINE_BUILTIN_FALLBACK1,
GCC_CHECK_MATH_INLINE_BUILTIN_FALLBACK2): New.
Diffstat (limited to 'libgfortran/configure')
-rwxr-xr-x | libgfortran/configure | 325 |
1 files changed, 325 insertions, 0 deletions
diff --git a/libgfortran/configure b/libgfortran/configure index d01654e7c4b..b4cf854ddb3 100755 --- a/libgfortran/configure +++ b/libgfortran/configure @@ -19848,6 +19848,150 @@ _ACEOF + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for fmaf" >&5 +$as_echo_n "checking for fmaf... " >&6; } +if ${gcc_cv_math_func_fmaf+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test x$gcc_no_link = xyes; then + as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5 +fi +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#ifdef HAVE_COMPLEX_H +#include <complex.h> +#endif +#ifdef HAVE_MATH_H +#include <math.h> +#endif + +int (*ptr)() = (int (*)())fmaf; + +int +main () +{ + return 0; +} + +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + gcc_cv_math_func_fmaf=yes +else + gcc_cv_math_func_fmaf=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_math_func_fmaf" >&5 +$as_echo "$gcc_cv_math_func_fmaf" >&6; } + if test $gcc_cv_math_func_fmaf = yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_FMAF 1 +_ACEOF + + fi + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for fma" >&5 +$as_echo_n "checking for fma... " >&6; } +if ${gcc_cv_math_func_fma+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test x$gcc_no_link = xyes; then + as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5 +fi +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#ifdef HAVE_COMPLEX_H +#include <complex.h> +#endif +#ifdef HAVE_MATH_H +#include <math.h> +#endif + +int (*ptr)() = (int (*)())fma; + +int +main () +{ + return 0; +} + +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + gcc_cv_math_func_fma=yes +else + gcc_cv_math_func_fma=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_math_func_fma" >&5 +$as_echo "$gcc_cv_math_func_fma" >&6; } + if test $gcc_cv_math_func_fma = yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_FMA 1 +_ACEOF + + fi + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for fmal" >&5 +$as_echo_n "checking for fmal... " >&6; } +if ${gcc_cv_math_func_fmal+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test x$gcc_no_link = xyes; then + as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5 +fi +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#ifdef HAVE_COMPLEX_H +#include <complex.h> +#endif +#ifdef HAVE_MATH_H +#include <math.h> +#endif + +int (*ptr)() = (int (*)())fmal; + +int +main () +{ + return 0; +} + +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + gcc_cv_math_func_fmal=yes +else + gcc_cv_math_func_fmal=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_math_func_fmal" >&5 +$as_echo "$gcc_cv_math_func_fmal" >&6; } + if test $gcc_cv_math_func_fmal = yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_FMAL 1 +_ACEOF + + fi + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for fmodf" >&5 $as_echo_n "checking for fmodf... " >&6; } if ${gcc_cv_math_func_fmodf+:} false; then : @@ -25559,6 +25703,187 @@ $as_echo "#define HAVE_CLOG 1" >>confdefs.h fi + + +if test $gcc_cv_math_func_copysign = no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inline __builtin_copysign" >&5 +$as_echo_n "checking for inline __builtin_copysign... " >&6; } +if ${gcc_cv_math_inline_builtin_copysign+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test x$gcc_no_link = xyes; then + as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5 +fi +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +double +copysign_fallback (double x, double y) +{ + return __builtin_copysign (x, y); +} + +int +main () +{ + return 0; +} + +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + gcc_cv_math_inline_builtin_copysign=yes +else + gcc_cv_math_inline_builtin_copysign=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_math_inline_builtin_copysign" >&5 +$as_echo "$gcc_cv_math_inline_builtin_copysign" >&6; } + if test $gcc_cv_math_inline_builtin_copysign = yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_INLINE_BUILTIN_COPYSIGN 1 +_ACEOF + + fi +fi + + +if test $gcc_cv_math_func_copysignl = no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inline __builtin_copysignl" >&5 +$as_echo_n "checking for inline __builtin_copysignl... " >&6; } +if ${gcc_cv_math_inline_builtin_copysignl+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test x$gcc_no_link = xyes; then + as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5 +fi +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +long double +copysignl_fallback (long double x, long double y) +{ + return __builtin_copysignl (x, y); +} + +int +main () +{ + return 0; +} + +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + gcc_cv_math_inline_builtin_copysignl=yes +else + gcc_cv_math_inline_builtin_copysignl=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_math_inline_builtin_copysignl" >&5 +$as_echo "$gcc_cv_math_inline_builtin_copysignl" >&6; } + if test $gcc_cv_math_inline_builtin_copysignl = yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_INLINE_BUILTIN_COPYSIGNL 1 +_ACEOF + + fi +fi + + +if test $gcc_cv_math_func_fabs = no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inline __builtin_fabs" >&5 +$as_echo_n "checking for inline __builtin_fabs... " >&6; } +if ${gcc_cv_math_inline_builtin_fabs+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test x$gcc_no_link = xyes; then + as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5 +fi +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +double +fabs_fallback (double x) +{ + return __builtin_fabs (x); +} + +int +main () +{ + return 0; +} + +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + gcc_cv_math_inline_builtin_fabs=yes +else + gcc_cv_math_inline_builtin_fabs=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_math_inline_builtin_fabs" >&5 +$as_echo "$gcc_cv_math_inline_builtin_fabs" >&6; } + if test $gcc_cv_math_inline_builtin_fabs = yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_INLINE_BUILTIN_FABS 1 +_ACEOF + + fi +fi + + +if test $gcc_cv_math_func_fabsl = no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inline __builtin_fabsl" >&5 +$as_echo_n "checking for inline __builtin_fabsl... " >&6; } +if ${gcc_cv_math_inline_builtin_fabsl+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test x$gcc_no_link = xyes; then + as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5 +fi +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +long double +fabsl_fallback (long double x) +{ + return __builtin_fabsl (x); +} + +int +main () +{ + return 0; +} + +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + gcc_cv_math_inline_builtin_fabsl=yes +else + gcc_cv_math_inline_builtin_fabsl=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_math_inline_builtin_fabsl" >&5 +$as_echo "$gcc_cv_math_inline_builtin_fabsl" >&6; } + if test $gcc_cv_math_inline_builtin_fabsl = yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_INLINE_BUILTIN_FABSL 1 +_ACEOF + + fi +fi + # Check whether the system has a working stat() { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the target stat is reliable" >&5 |