https://gcc.gnu.org/g:c88127e838fb0647c71e6cf5f0da9b34ae2d4505
commit c88127e838fb0647c71e6cf5f0da9b34ae2d4505 Author: Michael Meissner <[email protected]> Date: Wed Sep 30 21:46:17 2026 -0400 Use perl to convert fix scripts for 16-bit floating point This patch removes the ppc-fix* functions, and instead uses perl to generate these automatically from the soft-fp sources. 2026-09-30 Michael Meissner <[email protected]> libgcc/ * config/rs6000/convert-16bit-fp-fix: New perl script. * config/rs6000/t-float16: Remove static ppc-fix* functions. Instead generate these via the convert-16bit-fp-fix script. * config/rs6000/ppc-fixbfdi.c: Delete. * config/rs6000/ppc-fixbfsi.c: Likewise. * config/rs6000/ppc-fixbfti.c: Likewise. * config/rs6000/ppc-fixhfdi.c: Likewise. * config/rs6000/ppc-fixhfsi.c: Likewise. * config/rs6000/ppc-fixhfti.c: Likewise. * config/rs6000/ppc-fixunsbfdi.c: Likewise. * config/rs6000/ppc-fixunsbfsi.c: Likewise. * config/rs6000/ppc-fixunsbfti.c: Likewise. * config/rs6000/ppc-fixunshfdi.c: Likewise. * config/rs6000/ppc-fixunshfsi.c: Likewise. * config/rs6000/ppc-fixunshfti.c: Likewise. Diff: --- libgcc/config/rs6000/convert-16bit-fp-fix | 163 ++++++++++++++++++++++++++++++ libgcc/config/rs6000/ppc-fixbfdi.c | 71 ------------- libgcc/config/rs6000/ppc-fixbfsi.c | 71 ------------- libgcc/config/rs6000/ppc-fixbfti.c | 71 ------------- libgcc/config/rs6000/ppc-fixhfdi.c | 71 ------------- libgcc/config/rs6000/ppc-fixhfsi.c | 71 ------------- libgcc/config/rs6000/ppc-fixhfti.c | 71 ------------- libgcc/config/rs6000/ppc-fixunsbfdi.c | 71 ------------- libgcc/config/rs6000/ppc-fixunsbfsi.c | 71 ------------- libgcc/config/rs6000/ppc-fixunsbfti.c | 71 ------------- libgcc/config/rs6000/ppc-fixunshfdi.c | 71 ------------- libgcc/config/rs6000/ppc-fixunshfsi.c | 71 ------------- libgcc/config/rs6000/ppc-fixunshfti.c | 71 ------------- libgcc/config/rs6000/t-float16 | 95 +++++++++++++++-- 14 files changed, 252 insertions(+), 858 deletions(-) diff --git a/libgcc/config/rs6000/convert-16bit-fp-fix b/libgcc/config/rs6000/convert-16bit-fp-fix new file mode 100755 index 000000000000..473b2ca2d65b --- /dev/null +++ b/libgcc/config/rs6000/convert-16bit-fp-fix @@ -0,0 +1,163 @@ +#! /usr/bin/perl -w +# Convert a libgcc/soft-fp fix<fp><int> fuunction for the PowerPC + +# Copyright (C) 2020-2026 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/>. +# +# The PowerPC 16-bit floating point support is considering requiring +# 16-bit floating point arguments to the 32/64-bit scalar format in +# registers and similarly returning the 16-bit floating point return to +# a 32/64-bit scalar value. However, this presents a problem in that +# if a machine doesn't have instructions to do a conversion in +# hardware, you can't call the soft-fp conversion function using the +# native calling sequence. +# +# This perl script converts a fix<fp><int>.c. or fixuns<fp><int>.c file +# to do the conversion to BFtype (Google brain 16-bit float) or HFtype +# (IEEE 754 _Float16). It produces 2 functions, one that has the +# normal name and takes the normal arguments, and the other that adds a +# _gpr suffix and changes the 16-bit floating point to unsigned short. +# +# A typical fix* conversion file looks like: +# +# <copyright message> +# +# #include "soft-fp.h" +# #include "single.h" +# +# DItype +# __fixsfdi (SFtype a) +# { +# FP_DECL_EX; +# FP_DECL_S (A); +# UDItype r; +# +# FP_INIT_EXCEPTIONS; +# FP_UNPACK_RAW_S (A, a); +# FP_TO_INT_S (r, A, DI_BITS, 1); +# FP_HANDLE_EXCEPTIONS; +# +# return r; +# } + +use warnings; +use strict; +use Getopt::Std; + +use vars qw($opt_b $opt_h); + +$opt_b = 0; +$opt_h = 0; + +&getopts ("bh") || die "Useage $0 [-b] [-h] <input >output\n"; + +die "$0: Either -b or -h must be passed\n" if (!$opt_b && !$opt_h); +die "$0: Both -b and -h must not be passed\n" if ($opt_b && $opt_h); + +# Scan the input and put out the copyright message + +my $line; +my $input = $ARGV[0]; + +while ($line = <>) { + chomp $line; + + last if ($line =~ /^[#]include/); + print $line, "\n"; +} + +if ($input) { + print "/* Automatically converted from $input. */\n"; + print "\n"; +} + +# Change the include file from the floating point type to either half.h +# or brain.h. + +die "$0: No include files\n" if (! defined ($line)); + +my $inc = ($opt_h ? "half" : "brain"); + +do { + $line =~ s/(single|double|extended|half|quad)/$inc/; + print $line, "\n"; + $line = <>; + +} while (defined ($line) && $line =~ /^[#]include/); + +# Scoop up the rest of the file, convert the input and function to +# operate on HFtype or BFtype. + +die "$0: No main source\n" if (! defined ($line)); + +my @func = (); +my $u_letter = ($opt_h ? "H" : "B"); +my $l_letter = ($opt_h ? "h" : "b"); + +do { + chomp $line; + + # Function line + if ($line =~ /^__fix/) { + $line =~ s/[BDHST]F/${u_letter}F/; + $line =~ s/[bdhst]f/${l_letter}f/; + } + + $line =~ s/_(DECL|RAW|INT)_[BHDST]/_${1}_${u_letter}/; + + push (@func, $line); + $line = <>; + +} while (defined ($line)); + +# Print out the normal conversion function + +print "/* ${u_letter}Ftype passed in FPR registers. */\n"; + +foreach $line (@func) { + print $line, "\n"; +} + +# Print out the special GPR function. + +print "\n"; +print "/* ${u_letter}Ftype passed in GPR registers. */\n"; + +foreach $line (@func) { + + # Function header + if ($line =~ /^__(fix|fixuns)([bh]f)([sdt]i)/) { + $line = "__${1}${2}${3}_gpr (unsigned short us)"; + } + + # Add conversion from unsigned short + if ($line =~ /FP_INIT_EXCEPTIONS/) { + print " ${u_letter}Ftype a;\n"; + print " union ushort_${l_letter}f u;\n"; + print "\n"; + print " u.us = us;\n"; + print " a = u.${l_letter}f;\n"; + print "\n"; + } + + print $line, "\n"; +} + +# Done +exit 0; + diff --git a/libgcc/config/rs6000/ppc-fixbfdi.c b/libgcc/config/rs6000/ppc-fixbfdi.c deleted file mode 100644 index f263ae961029..000000000000 --- a/libgcc/config/rs6000/ppc-fixbfdi.c +++ /dev/null @@ -1,71 +0,0 @@ -/* 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/>. - - This is a clone of softfp/fixhfdi.c - - We provide 2 conversions, one that takes the BFtype in a floating point - register and the other takes it in a general purpose register that is used - when BFtype must be converted to the 32/64-bit scalar type. */ - -#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; -} - -DItype -__fixbfdi_gpr (unsigned short us) -{ - FP_DECL_EX; - FP_DECL_B (A); - UDItype r; - union ushort_bf u; - BFtype a; - - u.us = us; - a = u.bf; - - 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/ppc-fixbfsi.c b/libgcc/config/rs6000/ppc-fixbfsi.c deleted file mode 100644 index 13b8f1db97e7..000000000000 --- a/libgcc/config/rs6000/ppc-fixbfsi.c +++ /dev/null @@ -1,71 +0,0 @@ -/* 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/>. - - This is a clone of softfp/fixhfsi.c - - We provide 2 conversions, one that takes the BFtype in a floating point - register and the other takes it in a general purpose register that is used - when BFtype must be converted to the 32/64-bit scalar type. */ - -#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; -} - -SItype -__fixbfsi_gpr (unsigned short us) -{ - FP_DECL_EX; - FP_DECL_B (A); - USItype r; - union ushort_bf u; - BFtype a; - - u.us = us; - a = u.bf; - - 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/ppc-fixbfti.c b/libgcc/config/rs6000/ppc-fixbfti.c deleted file mode 100644 index 1cbabe9c715d..000000000000 --- a/libgcc/config/rs6000/ppc-fixbfti.c +++ /dev/null @@ -1,71 +0,0 @@ -/* 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/>. - - This is a clone of softfp/fixhfti.c - - We provide 2 conversions, one that takes the BFtype in a floating point - register and the other takes it in a general purpose register that is used - when BFtype must be converted to the 32/64-bit scalar type. */ - -#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; -} - -TItype -__fixbfti_gpr (unsigned short us) -{ - FP_DECL_EX; - FP_DECL_B (A); - UTItype r; - union ushort_bf u; - BFtype a; - - u.us = us; - a = u.bf; - - 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/ppc-fixhfdi.c b/libgcc/config/rs6000/ppc-fixhfdi.c deleted file mode 100644 index ff7070de0562..000000000000 --- a/libgcc/config/rs6000/ppc-fixhfdi.c +++ /dev/null @@ -1,71 +0,0 @@ -/* 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/>. - - This is a clone of softfp/fixhfdi.c - - We provide 2 conversions, one that takes the HFtype in a floating point - register and the other takes it in a general purpose register that is used - when HFtype must be converted to the 32/64-bit scalar type. */ - -#include "soft-fp.h" -#include "half.h" - -DItype -__fixhfdi (HFtype a) -{ - FP_DECL_EX; - FP_DECL_H (A); - UDItype r; - - FP_INIT_EXCEPTIONS; - FP_UNPACK_RAW_H (A, a); - FP_TO_INT_H (r, A, DI_BITS, 1); - FP_HANDLE_EXCEPTIONS; - - return r; -} - -DItype -__fixhfdi_gpr (unsigned short us) -{ - FP_DECL_EX; - FP_DECL_H (A); - UDItype r; - union ushort_hf u; - HFtype a; - - u.us = us; - a = u.hf; - - FP_INIT_EXCEPTIONS; - FP_UNPACK_RAW_H (A, a); - FP_TO_INT_H (r, A, DI_BITS, 1); - FP_HANDLE_EXCEPTIONS; - - return r; -} diff --git a/libgcc/config/rs6000/ppc-fixhfsi.c b/libgcc/config/rs6000/ppc-fixhfsi.c deleted file mode 100644 index 5031f7ffa0bf..000000000000 --- a/libgcc/config/rs6000/ppc-fixhfsi.c +++ /dev/null @@ -1,71 +0,0 @@ -/* 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/>. - - This is a clone of softfp/fixhfsi.c - - We provide 2 conversions, one that takes the HFtype in a floating point - register and the other takes it in a general purpose register that is used - when HFtype must be converted to the 32/64-bit scalar type. */ - -#include "soft-fp.h" -#include "half.h" - -SItype -__fixhfsi (HFtype a) -{ - FP_DECL_EX; - FP_DECL_H (A); - USItype r; - - FP_INIT_EXCEPTIONS; - FP_UNPACK_RAW_H (A, a); - FP_TO_INT_H (r, A, SI_BITS, 1); - FP_HANDLE_EXCEPTIONS; - - return r; -} - -SItype -__fixhfsi_gpr (unsigned short us) -{ - FP_DECL_EX; - FP_DECL_H (A); - USItype r; - union ushort_hf u; - HFtype a; - - u.us = us; - a = u.hf; - - FP_INIT_EXCEPTIONS; - FP_UNPACK_RAW_H (A, a); - FP_TO_INT_H (r, A, SI_BITS, 1); - FP_HANDLE_EXCEPTIONS; - - return r; -} diff --git a/libgcc/config/rs6000/ppc-fixhfti.c b/libgcc/config/rs6000/ppc-fixhfti.c deleted file mode 100644 index 4e7432c3c408..000000000000 --- a/libgcc/config/rs6000/ppc-fixhfti.c +++ /dev/null @@ -1,71 +0,0 @@ -/* 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/>. - - This is a clone of softfp/fixhfti.c - - We provide 2 conversions, one that takes the HFtype in a floating point - register and the other takes it in a general purpose register that is used - when HFtype must be converted to the 32/64-bit scalar type. */ - -#include "soft-fp.h" -#include "half.h" - -TItype -__fixhfti (HFtype a) -{ - FP_DECL_EX; - FP_DECL_H (A); - UTItype r; - - FP_INIT_EXCEPTIONS; - FP_UNPACK_RAW_H (A, a); - FP_TO_INT_H (r, A, TI_BITS, 1); - FP_HANDLE_EXCEPTIONS; - - return r; -} - -TItype -__fixhfti_gpr (unsigned short us) -{ - FP_DECL_EX; - FP_DECL_H (A); - UTItype r; - union ushort_hf u; - HFtype a; - - u.us = us; - a = u.hf; - - FP_INIT_EXCEPTIONS; - FP_UNPACK_RAW_H (A, a); - FP_TO_INT_H (r, A, TI_BITS, 1); - FP_HANDLE_EXCEPTIONS; - - return r; -} diff --git a/libgcc/config/rs6000/ppc-fixunsbfdi.c b/libgcc/config/rs6000/ppc-fixunsbfdi.c deleted file mode 100644 index 8ed6eab9554f..000000000000 --- a/libgcc/config/rs6000/ppc-fixunsbfdi.c +++ /dev/null @@ -1,71 +0,0 @@ -/* 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/>. - - This is a clone of softfp/fixhfdi.c - - We provide 2 conversions, one that takes the BFtype in a floating point - register and the other takes it in a general purpose register that is used - when BFtype must be converted to the 32/64-bit scalar type. */ - -#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; -} - -UDItype -__fixunsbfdi_gpr (unsigned short us) -{ - FP_DECL_EX; - FP_DECL_B (A); - UDItype r; - union ushort_bf u; - BFtype a; - - u.us = us; - a = u.bf; - - 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/ppc-fixunsbfsi.c b/libgcc/config/rs6000/ppc-fixunsbfsi.c deleted file mode 100644 index 75d492fde582..000000000000 --- a/libgcc/config/rs6000/ppc-fixunsbfsi.c +++ /dev/null @@ -1,71 +0,0 @@ -/* 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/>. - - This is a clone of softfp/fixunsbfsi.c - - We provide 2 conversions, one that takes the BFtype in a floating point - register and the other takes it in a general purpose register that is used - when BFtype must be converted to the 32/64-bit scalar type. */ - -#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; -} - -USItype -__fixunsbfsi_gpr (unsigned short us) -{ - FP_DECL_EX; - FP_DECL_B (A); - USItype r; - union ushort_bf u; - BFtype a; - - u.us = us; - a = u.bf; - - 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/ppc-fixunsbfti.c b/libgcc/config/rs6000/ppc-fixunsbfti.c deleted file mode 100644 index 52b8f5c32dce..000000000000 --- a/libgcc/config/rs6000/ppc-fixunsbfti.c +++ /dev/null @@ -1,71 +0,0 @@ -/* 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/>. - - This is a clone of softfp/fixhunshfti.c - - We provide 2 conversions, one that takes the BFtype in a floating point - register and the other takes it in a general purpose register that is used - when BFtype must be converted to the 32/64-bit scalar type. */ - -#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; -} - -UTItype -__fixunsbfti_gpr (unsigned short us) -{ - FP_DECL_EX; - FP_DECL_B (A); - UTItype r; - union ushort_bf u; - BFtype a; - - u.us = us; - a = u.bf; - - 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/ppc-fixunshfdi.c b/libgcc/config/rs6000/ppc-fixunshfdi.c deleted file mode 100644 index 0a694afa8387..000000000000 --- a/libgcc/config/rs6000/ppc-fixunshfdi.c +++ /dev/null @@ -1,71 +0,0 @@ -/* 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/>. - - This is a clone of softfp/fixhfdi.c - - We provide 2 conversions, one that takes the HFtype in a floating point - register and the other takes it in a general purpose register that is used - when HFtype must be converted to the 32/64-bit scalar type. */ - -#include "soft-fp.h" -#include "half.h" - -UDItype -__fixunshfdi (HFtype a) -{ - FP_DECL_EX; - FP_DECL_H (A); - UDItype r; - - FP_INIT_EXCEPTIONS; - FP_UNPACK_RAW_H (A, a); - FP_TO_INT_H (r, A, DI_BITS, 0); - FP_HANDLE_EXCEPTIONS; - - return r; -} - -UDItype -__fixunshfdi_gpr (unsigned short us) -{ - FP_DECL_EX; - FP_DECL_H (A); - UDItype r; - union ushort_hf u; - HFtype a; - - u.us = us; - a = u.hf; - - FP_INIT_EXCEPTIONS; - FP_UNPACK_RAW_H (A, a); - FP_TO_INT_H (r, A, DI_BITS, 0); - FP_HANDLE_EXCEPTIONS; - - return r; -} diff --git a/libgcc/config/rs6000/ppc-fixunshfsi.c b/libgcc/config/rs6000/ppc-fixunshfsi.c deleted file mode 100644 index fbc30ba3cb7c..000000000000 --- a/libgcc/config/rs6000/ppc-fixunshfsi.c +++ /dev/null @@ -1,71 +0,0 @@ -/* 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/>. - - This is a clone of softfp/fixunshfsi.c - - We provide 2 conversions, one that takes the HFtype in a floating point - register and the other takes it in a general purpose register that is used - when HFtype must be converted to the 32/64-bit scalar type. */ - -#include "soft-fp.h" -#include "half.h" - -USItype -__fixunshfsi (HFtype a) -{ - FP_DECL_EX; - FP_DECL_H (A); - USItype r; - - FP_INIT_EXCEPTIONS; - FP_UNPACK_RAW_H (A, a); - FP_TO_INT_H (r, A, SI_BITS, 0); - FP_HANDLE_EXCEPTIONS; - - return r; -} - -USItype -__fixunshfsi_gpr (unsigned short us) -{ - FP_DECL_EX; - FP_DECL_H (A); - USItype r; - union ushort_hf u; - HFtype a; - - u.us = us; - a = u.hf; - - FP_INIT_EXCEPTIONS; - FP_UNPACK_RAW_H (A, a); - FP_TO_INT_H (r, A, SI_BITS, 0); - FP_HANDLE_EXCEPTIONS; - - return r; -} diff --git a/libgcc/config/rs6000/ppc-fixunshfti.c b/libgcc/config/rs6000/ppc-fixunshfti.c deleted file mode 100644 index 38a98c3aeeaa..000000000000 --- a/libgcc/config/rs6000/ppc-fixunshfti.c +++ /dev/null @@ -1,71 +0,0 @@ -/* 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/>. - - This is a clone of softfp/fixhunshfti.c - - We provide 2 conversions, one that takes the HFtype in a floating point - register and the other takes it in a general purpose register that is used - when HFtype must be converted to the 32/64-bit scalar type. */ - -#include "soft-fp.h" -#include "half.h" - -UTItype -__fixunshfti (HFtype a) -{ - FP_DECL_EX; - FP_DECL_H (A); - UTItype r; - - FP_INIT_EXCEPTIONS; - FP_UNPACK_RAW_H (A, a); - FP_TO_INT_H (r, A, TI_BITS, 0); - FP_HANDLE_EXCEPTIONS; - - return r; -} - -UTItype -__fixunshfti_gpr (unsigned short us) -{ - FP_DECL_EX; - FP_DECL_H (A); - UTItype r; - union ushort_hf u; - HFtype a; - - u.us = us; - a = u.hf; - - FP_INIT_EXCEPTIONS; - FP_UNPACK_RAW_H (A, a); - FP_TO_INT_H (r, A, TI_BITS, 0); - FP_HANDLE_EXCEPTIONS; - - return r; -} diff --git a/libgcc/config/rs6000/t-float16 b/libgcc/config/rs6000/t-float16 index 6b548b084fef..61dc29e5fd9a 100644 --- a/libgcc/config/rs6000/t-float16 +++ b/libgcc/config/rs6000/t-float16 @@ -1,7 +1,7 @@ +PERL := perl + # _Float16 library support, source files in soft-ftp fp16_funcs = extendhf-sfdf2 truncsfdf-hf2 \ - ppc-fixhfsi ppc-fixhfdi ppc-fixhfti \ - ppc-fixunshfsi ppc-fixunshfdi ppc-fixunshfti \ ppc-floatsihf ppc-floatdihf ppc-floattihf \ ppc-floatunsihf ppc-floatundihf ppc-floatuntihf \ ppc-eqhf2 ppc-floatbitinthf ppc-fixhfbitint @@ -19,8 +19,6 @@ $(fp16_obj) : INTERNAL_CFLAGS += $(FP16_CFLAGS) bfp16_funcs = extendbf-sfdf2 truncsfdf-bf2 \ ppc-floatsibf ppc-floatdibf ppc-floattibf \ ppc-floatunsibf ppc-floatundibf ppc-floatuntibf \ - ppc-fixbfsi ppc-fixbfdi ppc-fixbfti \ - ppc-fixunsbfsi ppc-fixunsbfdi ppc-fixunsbfti \ ppc-eqbf2 ppc-floatbitintbf ppc-fixbfbitint bfp16_src = $(addprefix $(srcdir)/config/rs6000/,$(addsuffix .c,$(bfp16_funcs))) @@ -35,10 +33,79 @@ both_fp16_obj = $(addsuffix $(objext),$(both_fp16_funcs)) $(both_fp16_obj) : INTERNAL_CFLAGS += $(FP16_CFLAGS) +# Convert functions in soft-fp to powerpc, building 2 versions, one +# with normal __bf16/_Float16 arguments, and the other where we +# pass/return 16-bit floating point in gprs. + +float16_prefix = ppc- +float16_fix_orig = $(srcdir)/soft-fp/fixsfdi.c +float16_fixuns_orig = $(srcdir)/soft-fp/fixsfdi.c + +float16_fix_script = $(srcdir)/config/rs6000/convert-16bit-fp-fix + +# Convert fix* functions for _Float16 +fp16x_fix_funcs = fixhfti fixhfdi fixhfsi +fp16x_fix_src = $(addprefix $(float16_prefix),$(addsuffix .c,$(fp16x_fix_funcs))) +fp16x_fix_obj = $(addprefix $(float16_prefix),$(addsuffix $(objext),$(fp16x_fix_funcs))) + +fp16x_fixuns_funcs = fixunshfti fixunshfdi fixunshfsi +fp16x_fixuns_src = $(addprefix $(float16_prefix),$(addsuffix .c,$(fp16x_fixuns_funcs))) +fp16x_fixuns_obj = $(addprefix $(float16_prefix),$(addsuffix $(objext),$(fp16x_fixuns_funcs))) + +fp16x_all_funcs = $(fp16x_fix_funcs) $(fp16x_fixuns_funcs) +fp16x_all_src = $(fp16x_fix_src) $(fp16x_fixuns_src) +fp16x_all_obj = $(fp16x_fix_obj) $(fp16x_fixuns_obj) + +fp16x_fix_dep = $(float16_fix_orig) \ + $(float16_fix_script) \ + $(srcdir)/config/rs6000/t-float16 + +fp16x_fixuns_dep = $(float16_fixuns_orig) \ + $(float16_fix_script) \ + $(srcdir)/config/rs6000/t-float16 + +$(fp16x_fix_src) : $(fp16x_fix_dep) + $(PERL) $(float16_fix_script) -h $(float16_fix_orig) > $@ + +$(fp16x_fixuns_src) : $(fp16x_fixuns_dep) + $(PERL) $(float16_fix_script) -h $(float16_fixuns_orig) > $@ + +$(fp16x_all_obj) : INTERNAL_CFLAGS += $(FP16_CFLAGS) + +# Convert fix* functions for __bf12 +bfp16x_fix_funcs = fixbfti fixbfdi fixbfsi +bfp16x_fix_src = $(addprefix $(float16_prefix),$(addsuffix .c,$(bfp16x_fix_funcs))) +bfp16x_fix_obj = $(addprefix $(float16_prefix),$(addsuffix $(objext),$(bfp16x_fix_funcs))) + +bfp16x_fixuns_funcs = fixunsbfti fixunsbfdi fixunsbfsi +bfp16x_fixuns_src = $(addprefix $(float16_prefix),$(addsuffix .c,$(bfp16x_fixuns_funcs))) +bfp16x_fixuns_obj = $(addprefix $(float16_prefix),$(addsuffix $(objext),$(bfp16x_fixuns_funcs))) + +bfp16x_all_funcs = $(bfp16x_fix_funcs) $(bfp16x_fixuns_funcs) +bfp16x_all_src = $(bfp16x_fix_src) $(bfp16x_fixuns_src) +bfp16x_all_obj = $(bfp16x_fix_obj) $(bfp16x_fixuns_obj) + +bfp16x_fix_dep = $(float16_fix_orig) \ + $(float16_fix_script) \ + $(srcdir)/config/rs6000/t-float16 + +bfp16x_fixuns_dep = $(float16_fixuns_orig) \ + $(float16_fix_script) \ + $(srcdir)/config/rs6000/t-float16 + +$(bfp16x_fix_src) : $(bfp16x_fix_dep) + $(PERL) $(float16_fix_script) -b $(float16_fix_orig) > $@ + +$(bfp16x_fixuns_src) : $(bfp16x_fixuns_dep) + $(PERL) $(float16_fix_script) -b $(float16_fixuns_orig) > $@ + +$(bfp16x_all_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) $(both_fp16_src) +LIB2ADD_ST += $(fp16_src) $(bfp16_src) $(both_fp16_src) \ + $(fp16x_all_src) $(bfp16x_all_src) .PHONY: test-float16 clean-float16 @@ -59,7 +126,23 @@ test-float16: for x in $(bfp16_obj); do echo " $$x"; done; \ echo; \ echo "both_fp16_obj:"; \ - for x in $(bfp16_obj); do echo " $$x"; done; + for x in $(bfp16_obj); do echo " $$x"; done; \ + echo; \ + echo "fp16x_all_funcs:"; \ + for x in $(fp16x_all_funcs); do echo " $$x"; done; \ + echo; \ + echo "fp16x_all_src:"; \ + for x in $(fp16x_all_src); do echo " $$x"; done; \ + echo; \ + echo "fp16x_all_obj:"; \ + for x in $(fp16x_all_obj); do echo " $$x"; done; \ + echo; \ + echo "float16_prefix = $(float16_prefix)"; \ + echo "float16_fix_orig = $(float16_fix_orig)"; \ + echo "float16_fixuns_orig = $(float16_fixuns_orig)"; \ + echo "float16_fix_script = $(float16_fix_script)"; \ + echo clean-float16: @$(MULTICLEAN) multi-clean DO=clean-float16 + rm -f $(fp16x_all_src)
