https://gcc.gnu.org/g:4704606d06d972059343730f0cf5817ba16b446a

commit 4704606d06d972059343730f0cf5817ba16b446a
Author: Michael Meissner <[email protected]>
Date:   Fri Nov 6 15:08:08 2026 -0500

    Add HF/BF emulation functions to libgcc.
    
    This patch adds the necessary support in libgcc to allow using the machine
    independent 16-bit floating point support.
    
    2026-11-06  Michael Meissner  <[email protected]>
    
    libgcc/
    
            * config.host (powerpc*-*-linux*): Add HF/BF emulation functions to
            PowerPC libgcc.
            * config/rs6000/float16-eqbf.c: New file.
            * config/rs6000/float16-extendbfdf2.c: Likewise.
            * config/rs6000/float16-fixbfdi.c: Likewise.
            * config/rs6000/float16-fixbfsi.c: Likewise.
            * config/rs6000/float16-fixbft.c: Likewise.
            * config/rs6000/float16-fixunsbfdi.c: Likewise.
            * config/rs6000/float16-fixunsbfsi.c: Likewise.
            * config/rs6000/float16-fixunsbfti.c: Likewise.
            * config/rs6000/float16-floattibf.c: Likewise.
            * config/rs6000/float16-floatuntibf.c: Likewise.
            * config/rs6000/sfp-machine.h (_FP_NANFRAC_H): New macro.
            (_FP_NANFRAC_B): Likewise.
            (_FP_NANSIGN_H): Likewise.
            (_FP_NANSIGN_B): Likewise.
            (DFtype2): Add HF/BF emulation function declarations.
            (SFtype2): Likewise.
            (DItype2): Likewise.
            (UDItype2): Likewise.
            (SItype2): Likewise.
            (USItype2): Likewise.
            (TItype2): Likewise.
            (UTItype2): Likewise.
            (HFtype2): Likewise.
            (__eqhf2): Likewise.
            (__extendhfdf2): Likewise.
            (__extendhfsf2): Likewise.
            (__fixhfdi): Likewise.
            (__fixhfsi): Likewise.
            (__fixunshfdi): Likewise.
            (__fixunshfsi): Likewise.
            (__floatdihf): Likewise.
            (__floatsihf): Likewise.
            (__floatundihf): Likewise.
            (__floatunsihf): Likewise.
            (__truncdfhf2): Likewise.
            (__truncsfhf2): Likewise.
            (__fixhfti): Likewise.
            (__fixunshfti): Likewise.
            (__floattihf): Likewise.
            (__floatuntihf): Likewise.
            (BFtype2): Likewise.
            (__eqbf2): Likewise.
            (__extendbfsf2): Likewise.
            (__extendbfdf2): Likewise.
            (__fixbfdi): Likewise.
            (__fixbfsi): Likewise.
            (__fixunsbfdi): Likewise.
            (__fixunsbfsi): Likewise.
            (__floatdibf): Likewise.
            (__floatsibf): Likewise.
            (__floatundibf): Likewise.
            (__floatunsibf): Likewise.
            (__truncdfbf2): Likewise.
            (__truncsfbf2): Likewise.
            (__fixbfti): Likewise.
            (__fixunsbfti): Likewise.
            (__floattibf): Likewise.
            (__floatuntibf): Likewise.
            (__truncbfhf2): Likewise.
            (__trunchfbf2): Likewise.
            * config/rs6000/t-float16: New file.
            * configure.ac (powerpc*-*-linux*): Check if the PowerPC compiler
            supports _Float16 and __bf16 types.
            * configure: Regenerate.

Diff:
---
 libgcc/config.host                         |  4 ++
 libgcc/config/rs6000/float16-eqbf2.c       | 49 ++++++++++++++++++++
 libgcc/config/rs6000/float16-extendbfdf2.c | 53 ++++++++++++++++++++++
 libgcc/config/rs6000/float16-fixbfdi.c     | 45 +++++++++++++++++++
 libgcc/config/rs6000/float16-fixbfsi.c     | 45 +++++++++++++++++++
 libgcc/config/rs6000/float16-fixbfti.c     | 45 +++++++++++++++++++
 libgcc/config/rs6000/float16-fixunsbfdi.c  | 45 +++++++++++++++++++
 libgcc/config/rs6000/float16-fixunsbfsi.c  | 45 +++++++++++++++++++
 libgcc/config/rs6000/float16-fixunsbfti.c  | 45 +++++++++++++++++++
 libgcc/config/rs6000/float16-floattibf.c   | 45 +++++++++++++++++++
 libgcc/config/rs6000/float16-floatuntibf.c | 45 +++++++++++++++++++
 libgcc/config/rs6000/sfp-machine.h         | 72 ++++++++++++++++++++++++++++++
 libgcc/config/rs6000/t-float16             | 69 ++++++++++++++++++++++++++++
 libgcc/configure                           | 23 ++++++++++
 libgcc/configure.ac                        | 11 +++++
 15 files changed, 641 insertions(+)

diff --git a/libgcc/config.host b/libgcc/config.host
index 319d6cfe0eff..08f10b427f22 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -1305,6 +1305,10 @@ powerpc*-*-linux*)
                tmake_file="${tmake_file} rs6000/t-float128-p10-hw"
        fi
 
+       if test $libgcc_cv_powerpc_float16 = yes; then
+               tmake_file="${tmake_file} rs6000/t-float16"
+       fi
+
        extra_parts="$extra_parts ecrti.o ecrtn.o ncrti.o ncrtn.o"
        md_unwind_header=rs6000/linux-unwind.h
        ;;
diff --git a/libgcc/config/rs6000/float16-eqbf2.c 
b/libgcc/config/rs6000/float16-eqbf2.c
new file mode 100644
index 000000000000..8c127e4c0009
--- /dev/null
+++ b/libgcc/config/rs6000/float16-eqbf2.c
@@ -0,0 +1,49 @@
+/* Software floating-point emulation.
+   Return 0 iff a == b, 1 otherwise
+   Copyright (C) 2021-2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file into
+   combinations with other programs, and to distribute those
+   combinations without any restriction coming from the use of this
+   file.  (The Lesser General Public License restrictions do apply in
+   other respects; for example, they cover modification of the file,
+   and distribution when not linked into a combine executable.)
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "brain.h"
+
+CMPtype
+__eqbf2 (BFtype a, BFtype b)
+{
+  FP_DECL_EX;
+  FP_DECL_B (A);
+  FP_DECL_B (B);
+  CMPtype r;
+
+  FP_INIT_EXCEPTIONS;
+  FP_UNPACK_RAW_B (A, a);
+  FP_UNPACK_RAW_B (B, b);
+  FP_CMP_EQ_B (r, A, B, 1);
+  FP_HANDLE_EXCEPTIONS;
+
+  return r;
+}
+
+strong_alias (__eqbf2, __nebf2);
diff --git a/libgcc/config/rs6000/float16-extendbfdf2.c 
b/libgcc/config/rs6000/float16-extendbfdf2.c
new file mode 100644
index 000000000000..9bb970a9f177
--- /dev/null
+++ b/libgcc/config/rs6000/float16-extendbfdf2.c
@@ -0,0 +1,53 @@
+/* Software floating-point emulation.
+   Return an IEEE half converted to IEEE double
+   Copyright (C) 2021-2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file into
+   combinations with other programs, and to distribute those
+   combinations without any restriction coming from the use of this
+   file.  (The Lesser General Public License restrictions do apply in
+   other respects; for example, they cover modification of the file,
+   and distribution when not linked into a combine executable.)
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#define FP_NO_EXACT_UNDERFLOW
+#include "soft-fp.h"
+#include "half.h"
+#include "double.h"
+
+DFtype
+__extendhfdf2 (HFtype a)
+{
+  FP_DECL_EX;
+  FP_DECL_H (A);
+  FP_DECL_D (R);
+  DFtype r;
+
+  FP_INIT_EXCEPTIONS;
+  FP_UNPACK_RAW_H (A, a);
+#if _FP_W_TYPE_SIZE < _FP_FRACBITS_D
+  FP_EXTEND (D, H, 2, 1, R, A);
+#else
+  FP_EXTEND (D, H, 1, 1, R, A);
+#endif
+  FP_PACK_RAW_D (r, R);
+  FP_HANDLE_EXCEPTIONS;
+
+  return r;
+}
diff --git a/libgcc/config/rs6000/float16-fixbfdi.c 
b/libgcc/config/rs6000/float16-fixbfdi.c
new file mode 100644
index 000000000000..43873b5d0b08
--- /dev/null
+++ b/libgcc/config/rs6000/float16-fixbfdi.c
@@ -0,0 +1,45 @@
+/* Software floating-point emulation.
+   Convert a IEEE half to 64bit signed integer
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file into
+   combinations with other programs, and to distribute those
+   combinations without any restriction coming from the use of this
+   file.  (The Lesser General Public License restrictions do apply in
+   other respects; for example, they cover modification of the file,
+   and distribution when not linked into a combine executable.)
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "brain.h"
+
+DItype
+__fixbfdi (BFtype a)
+{
+  FP_DECL_EX;
+  FP_DECL_B (A);
+  UDItype r;
+
+  FP_INIT_EXCEPTIONS;
+  FP_UNPACK_RAW_B (A, a);
+  FP_TO_INT_B (r, A, DI_BITS, 1);
+  FP_HANDLE_EXCEPTIONS;
+
+  return r;
+}
diff --git a/libgcc/config/rs6000/float16-fixbfsi.c 
b/libgcc/config/rs6000/float16-fixbfsi.c
new file mode 100644
index 000000000000..2df3108bb81b
--- /dev/null
+++ b/libgcc/config/rs6000/float16-fixbfsi.c
@@ -0,0 +1,45 @@
+/* Software floating-point emulation.
+   Convert a IEEE half to 32bit signed integer
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file into
+   combinations with other programs, and to distribute those
+   combinations without any restriction coming from the use of this
+   file.  (The Lesser General Public License restrictions do apply in
+   other respects; for example, they cover modification of the file,
+   and distribution when not linked into a combine executable.)
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "brain.h"
+
+SItype
+__fixbfsi (BFtype a)
+{
+  FP_DECL_EX;
+  FP_DECL_B (A);
+  USItype r;
+
+  FP_INIT_EXCEPTIONS;
+  FP_UNPACK_RAW_B (A, a);
+  FP_TO_INT_B (r, A, SI_BITS, 1);
+  FP_HANDLE_EXCEPTIONS;
+
+  return r;
+}
diff --git a/libgcc/config/rs6000/float16-fixbfti.c 
b/libgcc/config/rs6000/float16-fixbfti.c
new file mode 100644
index 000000000000..2912261bf2d4
--- /dev/null
+++ b/libgcc/config/rs6000/float16-fixbfti.c
@@ -0,0 +1,45 @@
+/* Software floating-point emulation.
+   Convert IEEE half to 128bit signed integer
+   Copyright (C) 2007-2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file into
+   combinations with other programs, and to distribute those
+   combinations without any restriction coming from the use of this
+   file.  (The Lesser General Public License restrictions do apply in
+   other respects; for example, they cover modification of the file,
+   and distribution when not linked into a combine executable.)
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "brain.h"
+
+TItype
+__fixbfti (BFtype a)
+{
+  FP_DECL_EX;
+  FP_DECL_B (A);
+  UTItype r;
+
+  FP_INIT_EXCEPTIONS;
+  FP_UNPACK_RAW_B (A, a);
+  FP_TO_INT_B (r, A, TI_BITS, 1);
+  FP_HANDLE_EXCEPTIONS;
+
+  return r;
+}
diff --git a/libgcc/config/rs6000/float16-fixunsbfdi.c 
b/libgcc/config/rs6000/float16-fixunsbfdi.c
new file mode 100644
index 000000000000..c86949d2d473
--- /dev/null
+++ b/libgcc/config/rs6000/float16-fixunsbfdi.c
@@ -0,0 +1,45 @@
+/* Software floating-point emulation.
+   Convert IEEE half to 64bit unsigned integer
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file into
+   combinations with other programs, and to distribute those
+   combinations without any restriction coming from the use of this
+   file.  (The Lesser General Public License restrictions do apply in
+   other respects; for example, they cover modification of the file,
+   and distribution when not linked into a combine executable.)
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "brain.h"
+
+UDItype
+__fixunsbfdi (BFtype a)
+{
+  FP_DECL_EX;
+  FP_DECL_B (A);
+  UDItype r;
+
+  FP_INIT_EXCEPTIONS;
+  FP_UNPACK_RAW_B (A, a);
+  FP_TO_INT_B (r, A, DI_BITS, 0);
+  FP_HANDLE_EXCEPTIONS;
+
+  return r;
+}
diff --git a/libgcc/config/rs6000/float16-fixunsbfsi.c 
b/libgcc/config/rs6000/float16-fixunsbfsi.c
new file mode 100644
index 000000000000..c2a198c2849b
--- /dev/null
+++ b/libgcc/config/rs6000/float16-fixunsbfsi.c
@@ -0,0 +1,45 @@
+/* Software floating-point emulation.
+   Convert IEEE half to 32bit unsigned integer
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file into
+   combinations with other programs, and to distribute those
+   combinations without any restriction coming from the use of this
+   file.  (The Lesser General Public License restrictions do apply in
+   other respects; for example, they cover modification of the file,
+   and distribution when not linked into a combine executable.)
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "brain.h"
+
+USItype
+__fixunsbfsi (BFtype a)
+{
+  FP_DECL_EX;
+  FP_DECL_B (A);
+  USItype r;
+
+  FP_INIT_EXCEPTIONS;
+  FP_UNPACK_RAW_B (A, a);
+  FP_TO_INT_B (r, A, SI_BITS, 0);
+  FP_HANDLE_EXCEPTIONS;
+
+  return r;
+}
diff --git a/libgcc/config/rs6000/float16-fixunsbfti.c 
b/libgcc/config/rs6000/float16-fixunsbfti.c
new file mode 100644
index 000000000000..9ecfec6b14eb
--- /dev/null
+++ b/libgcc/config/rs6000/float16-fixunsbfti.c
@@ -0,0 +1,45 @@
+/* Software floating-point emulation.
+   Convert IEEE half to 128bit unsigned integer
+   Copyright (C) 2007-2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file into
+   combinations with other programs, and to distribute those
+   combinations without any restriction coming from the use of this
+   file.  (The Lesser General Public License restrictions do apply in
+   other respects; for example, they cover modification of the file,
+   and distribution when not linked into a combine executable.)
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "brain.h"
+
+UTItype
+__fixunsbfti (BFtype a)
+{
+  FP_DECL_EX;
+  FP_DECL_B (A);
+  UTItype r;
+
+  FP_INIT_EXCEPTIONS;
+  FP_UNPACK_RAW_B (A, a);
+  FP_TO_INT_B (r, A, TI_BITS, 0);
+  FP_HANDLE_EXCEPTIONS;
+
+  return r;
+}
diff --git a/libgcc/config/rs6000/float16-floattibf.c 
b/libgcc/config/rs6000/float16-floattibf.c
new file mode 100644
index 000000000000..57c5650a27dd
--- /dev/null
+++ b/libgcc/config/rs6000/float16-floattibf.c
@@ -0,0 +1,45 @@
+/* Software floating-point emulation.
+   Convert a 128bit signed integer to IEEE half
+   Copyright (C) 2007-2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file into
+   combinations with other programs, and to distribute those
+   combinations without any restriction coming from the use of this
+   file.  (The Lesser General Public License restrictions do apply in
+   other respects; for example, they cover modification of the file,
+   and distribution when not linked into a combine executable.)
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "half.h"
+
+HFtype
+__floattihf (TItype i)
+{
+  FP_DECL_EX;
+  FP_DECL_H (A);
+  HFtype a;
+
+  FP_INIT_ROUNDMODE;
+  FP_FROM_INT_H (A, i, TI_BITS, UTItype);
+  FP_PACK_RAW_H (a, A);
+  FP_HANDLE_EXCEPTIONS;
+
+  return a;
+}
diff --git a/libgcc/config/rs6000/float16-floatuntibf.c 
b/libgcc/config/rs6000/float16-floatuntibf.c
new file mode 100644
index 000000000000..a9571427010f
--- /dev/null
+++ b/libgcc/config/rs6000/float16-floatuntibf.c
@@ -0,0 +1,45 @@
+/* Software floating-point emulation.
+   Convert a 128bit unsigned integer to IEEE half.
+   Copyright (C) 2007-2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file into
+   combinations with other programs, and to distribute those
+   combinations without any restriction coming from the use of this
+   file.  (The Lesser General Public License restrictions do apply in
+   other respects; for example, they cover modification of the file,
+   and distribution when not linked into a combine executable.)
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include "soft-fp.h"
+#include "brain.h"
+
+BFtype
+__floatuntibf (UTItype i)
+{
+  FP_DECL_EX;
+  FP_DECL_B (A);
+  BFtype a;
+
+  FP_INIT_ROUNDMODE;
+  FP_FROM_INT_B (A, i, TI_BITS, UTItype);
+  FP_PACK_RAW_B (a, A);
+  FP_HANDLE_EXCEPTIONS;
+
+  return a;
+}
diff --git a/libgcc/config/rs6000/sfp-machine.h 
b/libgcc/config/rs6000/sfp-machine.h
index f0ede0e042a3..12db179b9549 100644
--- a/libgcc/config/rs6000/sfp-machine.h
+++ b/libgcc/config/rs6000/sfp-machine.h
@@ -22,6 +22,9 @@ typedef unsigned int UTItype __attribute__ ((mode (TI)));
 #define _FP_I_TYPE             int
 #endif /* 32-bits  */
 
+#define _FP_NANFRAC_H           _FP_QNANBIT_H
+#define _FP_NANFRAC_B           _FP_QNANBIT_B
+
 /* The type of the result of a floating point comparison.  This must
    match `__libgcc_cmp_return__' in GCC for the target.  */
 typedef int __gcc_CMPtype __attribute__ ((mode (__libgcc_cmp_return__)));
@@ -62,6 +65,8 @@ typedef int __gcc_CMPtype __attribute__ ((mode 
(__libgcc_cmp_return__)));
 #define _FP_NANFRAC_Q          ((_FP_QNANBIT_Q << 1) - 1), -1, -1, -1
 #endif
 
+#define _FP_NANSIGN_H          1
+#define _FP_NANSIGN_B          1
 #define _FP_NANSIGN_S          0
 #define _FP_NANSIGN_D          0
 #define _FP_NANSIGN_Q          0
@@ -161,3 +166,70 @@ void __sfp_handle_exceptions (int);
 # define strong_alias(name, aliasname) _strong_alias(name, aliasname)
 # define _strong_alias(name, aliasname) \
   extern __typeof (name) aliasname __attribute__ ((alias (#name)));
+
+/* Add prototypes for the HFmode and BFmode functions.  */
+typedef double DFtype2;
+typedef float SFtype2;
+typedef int DItype2 __attribute__ ((mode (DI)));
+typedef unsigned int UDItype2 __attribute__ ((mode (DI)));
+typedef int SItype2 __attribute__ ((mode (SI)));
+typedef unsigned int USItype2 __attribute__ ((mode (SI)));
+#ifdef _ARCH_PPC64
+typedef int TItype2 __attribute__ ((mode (TI)));
+typedef unsigned int UTItype2 __attribute__ ((mode (TI)));
+#endif
+
+#ifdef __FLOAT16__
+typedef float HFtype2 __attribute__ ((mode (HF)));
+
+extern CMPtype __eqhf2 (HFtype2, HFtype2);
+extern DFtype2 __extendhfdf2 (HFtype2);
+extern SFtype2 __extendhfsf2 (HFtype2);
+extern DItype2 __fixhfdi (HFtype2);
+extern SItype2 __fixhfsi (HFtype2);
+extern UDItype2 __fixunshfdi (HFtype2);
+extern USItype2 __fixunshfsi (HFtype2);
+extern HFtype2 __floatdihf (DItype2);
+extern HFtype2 __floatsihf (SItype2);
+extern HFtype2 __floatundihf (UDItype2);
+extern HFtype2 __floatunsihf (USItype2);
+extern HFtype2 __truncdfhf2 (DFtype2);
+extern HFtype2 __truncsfhf2 (SFtype2);
+
+#ifdef _ARCH_PPC64
+extern TItype2 __fixhfti (HFtype2);
+extern UTItype2 __fixunshfti (HFtype2);
+extern HFtype2 __floattihf (TItype2);
+extern HFtype2 __floatuntihf (UTItype2);
+#endif
+#endif
+
+#ifdef __BFLOAT16__
+typedef float BFtype2 __attribute__ ((mode (BF)));
+
+extern CMPtype __eqbf2 (BFtype2, BFtype2);
+extern SFtype2 __extendbfsf2 (BFtype2);
+extern DFtype2 __extendbfdf2 (BFtype2);
+extern DItype2 __fixbfdi (BFtype2);
+extern SItype2 __fixbfsi (BFtype2);
+extern UDItype2 __fixunsbfdi (BFtype2);
+extern USItype2 __fixunsbfsi (BFtype2);
+extern BFtype2 __floatdibf (DItype2);
+extern BFtype2 __floatsibf (SItype2);
+extern BFtype2 __floatundibf (UDItype2);
+extern BFtype2 __floatunsibf (USItype2);
+extern BFtype2 __truncdfbf2 (DFtype2);
+extern BFtype2 __truncsfbf2 (SFtype2);
+
+#ifdef _ARCH_PPC64
+extern TItype2 __fixbfti (BFtype2);
+extern UTItype2 __fixunsbfti (BFtype2);
+extern BFtype2 __floattibf (TItype2);
+extern BFtype2 __floatuntibf (UTItype2);
+#endif
+#endif
+
+#if defined(__FLOAT16__) && defined(__BFLOAT16__)
+extern HFtype2 __truncbfhf2 (BFtype2);
+extern BFtype2 __trunchfbf2 (HFtype2);
+#endif
diff --git a/libgcc/config/rs6000/t-float16 b/libgcc/config/rs6000/t-float16
new file mode 100644
index 000000000000..c8daef917183
--- /dev/null
+++ b/libgcc/config/rs6000/t-float16
@@ -0,0 +1,69 @@
+# _Float16 library support
+
+fp16_funcs     = eqhf2 extendhfdf2 extendhfsf2 \
+                 fixhfsi  fixhfdi fixhfti fixunshfsi fixunshfdi fixunshfti \
+                 floatsihf floatdihf floattihf floatunsihf floatundihf 
floatuntihf \
+                 truncdfhf2 truncsfhf2
+
+fp16_src       = $(addprefix $(srcdir)/soft-fp/,$(addsuffix .c,$(fp16_funcs)))
+fp16_obj       = $(addsuffix $(objext),$(fp16_funcs))
+
+FP16_CFLAGS    = -mfloat16 -Wno-psabi \
+                 -I$(srcdir)/soft-fp -I$(srcdir)/config/rs6000
+
+$(fp16_obj)    : INTERNAL_CFLAGS += $(FP16_CFLAGS)
+
+# __bfloat16 library support
+
+bfp16_funcs    = extendbfsf2 floatdibf floatsibf floatundibf floatunsibf \
+                 truncdfbf2 truncsfbf2
+
+bfp16_src      = $(addprefix $(srcdir)/soft-fp/,$(addsuffix .c,$(bfp16_funcs)))
+bfp16_obj      = $(addsuffix $(objext),$(bfp16_funcs))
+
+bfp16_funcs2   = float16-eqbf2 float16-extendbfdf2 \
+                 float16-fixbfsi float16-fixbfdi float16-fixbfti \
+                 float16-fixunsbfsi float16-fixunsbfdi float16-fixunsbfti \
+                 float16-floattibf float16-floatuntibf
+bfp16_src2     = $(addprefix $(srcdir)/config/rs6000/,$(addsuffix 
.c,$(bfp16_funcs2)))
+bfp16_obj2     = $(addsuffix $(objext),$(bfp16_funcs2))
+
+$(bfp16_obj)   : INTERNAL_CFLAGS += $(FP16_CFLAGS)
+$(bfp16_obj2)  : INTERNAL_CFLAGS += $(FP16_CFLAGS)
+
+# Conversion between __bfloat16 and _Float16
+
+both_fp16_funcs         = truncbfhf2 trunchfbf2
+both_fp16_src   = $(addprefix $(srcdir)/soft-fp/,$(addsuffix 
.c,$(both_fp16_funcs)))
+both_fp16_obj   = $(addsuffix $(objext),$(both_fp16_funcs))
+
+$(both_fp16_obj) : INTERNAL_CFLAGS += $(FP16_CFLAGS)
+
+# For now, only put it in the static library
+# LIB2ADD      += $(fp16_src) $(bfp16_src) $(both_fp16_src)
+
+LIB2ADD_ST     += $(fp16_src) $(bfp16_src) $(bfp16_src2) $(both_fp16_src)
+
+.PHONY: test-float16 clean-float16
+
+test-float16:
+       @echo "fp16_src:"; \
+       for x in $(fp16_src); do echo "    $$x"; done; \
+       echo; \
+       echo "bfp16_src:"; \
+       for x in $(bfp16_src); do echo "    $$x"; done; \
+       echo; \
+       echo "both_fp16_src:"; \
+       for x in $(both_fp16_src); do echo "    $$x"; done; \
+       echo; \
+       echo "fp16_obj:"; \
+       for x in $(fp16_obj); do echo "    $$x"; done; \
+       echo; \
+       echo "bfp16_obj:"; \
+       for x in $(bfp16_obj); do echo "    $$x"; done; \
+       echo; \
+       echo "both_fp16_obj:"; \
+       for x in $(bfp16_obj); do echo "    $$x"; done;
+
+clean-float16:
+       @$(MULTICLEAN) multi-clean DO=clean-float16
diff --git a/libgcc/configure b/libgcc/configure
index a3f6a4a9650b..945c535154fb 100755
--- a/libgcc/configure
+++ b/libgcc/configure
@@ -5137,6 +5137,8 @@ case ${host} in
 # check if we have VSX (ISA 2.06) support to build the software libraries, and
 # whether the assembler can handle xsaddqp for hardware support.  Also check if
 # a new glibc is being used so that __builtin_cpu_supports can be used.
+#
+# Add float16 support also
 powerpc*-*-linux*)
   saved_CFLAGS="$CFLAGS"
   CFLAGS="$CFLAGS -mabi=altivec -mvsx -mfloat128"
@@ -5231,6 +5233,27 @@ 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"
+
+  CFLAGS="$CFLAGS -mfloat16 -Wno-psabi"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the PowerPC can 
build the _Float16 libraries" >&5
+$as_echo_n "checking whether the PowerPC can build the _Float16 libraries... " 
>&6; }
+if ${libgcc_cv_powerpc_float16+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+_Float16 addf16 (_Float16 a, _Float16 b) { return a + b; }
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  libgcc_cv_powerpc_float16=yes
+else
+  libgcc_cv_powerpc_float16=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_float16" 
>&5
+$as_echo "$libgcc_cv_powerpc_float16" >&6; }
+  CFLAGS="$saved_CFLAGS"
 esac
 
 case ${host} in
diff --git a/libgcc/configure.ac b/libgcc/configure.ac
index 479cff4b2376..61e53916f19c 100644
--- a/libgcc/configure.ac
+++ b/libgcc/configure.ac
@@ -418,6 +418,8 @@ case ${host} in
 # check if we have VSX (ISA 2.06) support to build the software libraries, and
 # whether the assembler can handle xsaddqp for hardware support.  Also check if
 # a new glibc is being used so that __builtin_cpu_supports can be used.
+#
+# Add float16 support also
 powerpc*-*-linux*)
   saved_CFLAGS="$CFLAGS"
   CFLAGS="$CFLAGS -mabi=altivec -mvsx -mfloat128"
@@ -476,6 +478,15 @@ powerpc*-*-linux*)
     [libgcc_cv_powerpc_3_1_float128_hw=yes],
     [libgcc_cv_powerpc_3_1_float128_hw=no])])
   CFLAGS="$saved_CFLAGS"
+
+  CFLAGS="$CFLAGS -mfloat16 -Wno-psabi"
+  AC_CACHE_CHECK([whether the PowerPC can build the _Float16 libraries],
+                [libgcc_cv_powerpc_float16],
+                [AC_COMPILE_IFELSE(
+    [AC_LANG_SOURCE([_Float16 addf16 (_Float16 a, _Float16 b) { return a + b; 
}])],
+    [libgcc_cv_powerpc_float16=yes],
+    [libgcc_cv_powerpc_float16=no])])
+  CFLAGS="$saved_CFLAGS"
 esac
 
 case ${host} in

Reply via email to