[PATCH V2] powerpc: properly check for feenableexcept() on FreeBSD

2022-05-03 Thread pkubaj
From: Piotr Kubaj 

FreeBSD/powerpc* has feenableexcept() defined in fenv.h header.

Signed-off-by: Piotr Kubaj 
---
 libgfortran/configure| 41 +++-
 libgfortran/configure.ac | 17 -
 2 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/libgfortran/configure b/libgfortran/configure
index ae64dca3114..ad71694ef05 100755
--- a/libgfortran/configure
+++ b/libgfortran/configure
@@ -27338,8 +27338,45 @@ fi
 
 
 
+case x$target in
+  xpowerpc*-freebsd*)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fenv.h and 
feenableexcept" >&5
+$as_echo_n "checking for fenv.h and feenableexcept... " >&6; }
+if ${have_feenableexcept+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+ #include 
+int
+main ()
+{
+ feenableexcept(FE_DIVBYZERO | FE_INVALID);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+   have_feenableexcept="yes"
+else
+   have_feenableexcept="no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_feenableexcept" >&5
+$as_echo "$have_feenableexcept" >&6; }
+if test "x$have_feenableexcept" = "xyes"; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_FEENABLEEXCEPT 1
+_ACEOF
+
+fi;
+;;
+  *)
 # Check for GNU libc feenableexcept
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for feenableexcept in -lm" 
>&5
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for feenableexcept in 
-lm" >&5
 $as_echo_n "checking for feenableexcept in -lm... " >&6; }
 if ${ac_cv_lib_m_feenableexcept+:} false; then :
   $as_echo_n "(cached) " >&6
@@ -27384,6 +27421,8 @@ $as_echo "#define HAVE_FEENABLEEXCEPT 1" >>confdefs.h
 
 fi
 
+;;
+esac
 
 # At least for glibc, clock_gettime is in librt.  But don't
 # pull that in if it still doesn't give us the function we want.  This
diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac
index 97cc490cb5e..2dd6d345b22 100644
--- a/libgfortran/configure.ac
+++ b/libgfortran/configure.ac
@@ -602,8 +602,23 @@ fi
 # Check whether we have a __float128 type, depends on 
enable_libquadmath_support
 LIBGFOR_CHECK_FLOAT128
 
+case x$target in
+  xpowerpc*-freebsd*)
+AC_CACHE_CHECK([for fenv.h and feenableexcept], have_feenableexcept, [
+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+[[ #include   ]],
+[[ feenableexcept(FE_DIVBYZERO | FE_INVALID); ]])],
+[ have_feenableexcept="yes" ],
+[ have_feenableexcept="no"  ])])
+if test "x$have_feenableexcept" = "xyes"; then
+  AC_DEFINE(HAVE_FEENABLEEXCEPT,1,[fenv.h includes feenableexcept])
+fi;
+;;
+  *)
 # Check for GNU libc feenableexcept
-AC_CHECK_LIB([m],[feenableexcept],[have_feenableexcept=yes 
AC_DEFINE([HAVE_FEENABLEEXCEPT],[1],[libm includes feenableexcept])])
+AC_CHECK_LIB([m],[feenableexcept],[have_feenableexcept=yes 
AC_DEFINE([HAVE_FEENABLEEXCEPT],[1],[libm includes feenableexcept])])
+;;
+esac
 
 # At least for glibc, clock_gettime is in librt.  But don't
 # pull that in if it still doesn't give us the function we want.  This
-- 
2.36.0



[PATCH] libgcc: allow building float128 libraries on FreeBSD

2022-02-20 Thread pkubaj
From: Piotr Kubaj 

While FreeBSD currently uses 64-bit long double, there should be no
problem with adding support for float128.

Signed-off-by: Piotr Kubaj 
---
 libgcc/configure| 22 ++
 libgcc/configure.ac | 11 +++
 2 files changed, 33 insertions(+)

diff --git a/libgcc/configure b/libgcc/configure
index 4919a56f518..334d20d1fb1 100755
--- a/libgcc/configure
+++ b/libgcc/configure
@@ -5300,6 +5300,28 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: 
$libgcc_cv_powerpc_3_1_float128_hw" >&5
 $as_echo "$libgcc_cv_powerpc_3_1_float128_hw" >&6; }
   CFLAGS="$saved_CFLAGS"
+;;
+powerpc*-*-freebsd*)
+  saved_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -mabi=altivec -mvsx -mfloat128"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for PowerPC ISA 2.06 to 
build __float128 libraries" >&5
+$as_echo_n "checking for PowerPC ISA 2.06 to build __float128 libraries... " 
>&6; }
+if ${libgcc_cv_powerpc_float128+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+vector double dadd (vector double a, vector double b) { return a + b; }
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  libgcc_cv_powerpc_float128=yes
+else
+  libgcc_cv_powerpc_float128=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libgcc_cv_powerpc_float128" 
>&5
+$as_echo "$libgcc_cv_powerpc_float128" >&6; }
 esac
 
 # Collect host-machine-specific information.
diff --git a/libgcc/configure.ac b/libgcc/configure.ac
index 13a80b2551b..99ec5d405a4 100644
--- a/libgcc/configure.ac
+++ b/libgcc/configure.ac
@@ -483,6 +483,17 @@ powerpc*-*-linux*)
 [libgcc_cv_powerpc_3_1_float128_hw=yes],
 [libgcc_cv_powerpc_3_1_float128_hw=no])])
   CFLAGS="$saved_CFLAGS"
+;;
+powerpc*-*-freebsd*)
+  saved_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -mabi=altivec -mvsx -mfloat128"
+  AC_CACHE_CHECK([for PowerPC ISA 2.06 to build __float128 libraries],
+ [libgcc_cv_powerpc_float128],
+ [AC_COMPILE_IFELSE(
+[AC_LANG_SOURCE([vector double dadd (vector double a, vector double b) { 
return a + b; }])],
+[libgcc_cv_powerpc_float128=yes],
+[libgcc_cv_powerpc_float128=no])])
+  CFLAGS="$saved_CFLAGS"
 esac
 
 # Collect host-machine-specific information.
-- 
2.35.1