From 686eaed286251caaedf48c7d17d7f443170d6dde Mon Sep 17 00:00:00 2001
From: Willem Jan Palenstijn <wjp@usecode.org>
Date: Sun, 29 Oct 2017 13:25:59 +0100
Subject: [PATCH] Attempt to handle __mips_single_float in libgcc
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch to libgcc is an adapted version of the patch by
Jürgen Urban at https://patchwork.ozlabs.org/patch/359867/ , taking
into account the suggestion by Matthew Fortune to check
__mips_single_float in libgcc's configure.
---
 libgcc/config.host        |  8 ++++++--
 libgcc/config/t-hardfp-sf | 32 ++++++++++++++++++++++++++++++++
 libgcc/configure          | 20 ++++++++++++++++++++
 libgcc/configure.ac       |  8 ++++++++
 4 files changed, 66 insertions(+), 2 deletions(-)
 create mode 100644 libgcc/config/t-hardfp-sf

diff --git a/libgcc/config.host b/libgcc/config.host
index 4c9bb52d126..d74613a1dbc 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -140,11 +140,15 @@ microblaze*-*-*)
 	cpu_type=microblaze
 	;;
 mips*-*-*)
-	# All MIPS targets provide a full set of FP routines.
 	cpu_type=mips
 	tmake_file="mips/t-mips"
 	if test "${libgcc_cv_mips_hard_float}" = yes; then
-		tmake_file="${tmake_file} t-hardfp-sfdf t-hardfp"
+		if test "${libgcc_cv_mips_single_float}" = yes; then
+			tmake_file="${tmake_file} t-hardfp-sf"
+		else
+			tmake_file="${tmake_file} t-hardfp-sfdf"
+		fi
+		tmake_file="${tmake_file} t-hardfp"
 	else
 		tmake_file="${tmake_file} t-softfp-sfdf"
 	fi
diff --git a/libgcc/config/t-hardfp-sf b/libgcc/config/t-hardfp-sf
new file mode 100644
index 00000000000..10682690219
--- /dev/null
+++ b/libgcc/config/t-hardfp-sf
@@ -0,0 +1,32 @@
+# Copyright (C) 2014 Free Software Foundation, Inc.
+
+# This file is part of GCC.
+
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+hardfp_float_modes := sf
+# di and ti are provided by libgcc2.c where needed.
+hardfp_int_modes := si
+hardfp_extensions := 
+hardfp_truncations := 
+
+# Emulate 64 bit float:
+FPBIT = true
+DPBIT = true
+# Don't build functions handled by 32 bit hardware:
+LIB2FUNCS_EXCLUDE = _addsub_sf _mul_sf _div_sf \
+    _fpcmp_parts_sf _compare_sf _eq_sf _ne_sf _gt_sf _ge_sf \
+    _lt_sf _le_sf _unord_sf _si_to_sf _sf_to_si _negate_sf \
+    _thenan_sf _sf_to_usi _usi_to_sf
diff --git a/libgcc/configure b/libgcc/configure
index 35896deb7bf..b04e158e155 100644
--- a/libgcc/configure
+++ b/libgcc/configure
@@ -4352,6 +4352,26 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libgcc_cv_mips_hard_float" >&5
 $as_echo "$libgcc_cv_mips_hard_float" >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the target is single-float" >&5
+$as_echo_n "checking whether the target is single-float... " >&6; }
+if test "${libgcc_cv_mips_single_float+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifndef __mips_single_float
+     #error FOO
+     #endif
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  libgcc_cv_mips_single_float=yes
+else
+  libgcc_cv_mips_single_float=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libgcc_cv_mips_single_float" >&5
+$as_echo "$libgcc_cv_mips_single_float" >&6; }
 esac
 
 # Collect host-machine-specific information.
diff --git a/libgcc/configure.ac b/libgcc/configure.ac
index d877d21c092..312bf264679 100644
--- a/libgcc/configure.ac
+++ b/libgcc/configure.ac
@@ -302,6 +302,14 @@ mips*-*-*)
      #endif],
     [libgcc_cv_mips_hard_float=yes],
     [libgcc_cv_mips_hard_float=no])])
+  AC_CACHE_CHECK([whether the target is single-float],
+		 [libgcc_cv_mips_single_float],
+		 [AC_COMPILE_IFELSE(
+    [#ifndef __mips_single_float
+     #error FOO
+     #endif],
+    [libgcc_cv_mips_single_float=yes],
+    [libgcc_cv_mips_single_float=no])])
 esac
 
 # Collect host-machine-specific information.
-- 
2.11.0

