https://gcc.gnu.org/g:27768788284e338fc571be13b4bf647a2cdaecf3
commit 27768788284e338fc571be13b4bf647a2cdaecf3 Author: Michael Meissner <[email protected]> Date: Wed Sep 30 22:57:21 2026 -0400 Use perl to convert fix/float bitint functions for 16-bit floating point This patch removes the ppc-fix*bitint and ppc-float*bitint 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: Add support for bitint. * config/rs6000/t-float16: Likewise. * config/rs6000/ppc-fixbfbitint.c: Delete. * config/rs6000/ppc-fixhfbitint.c: Likewise. * config/rs6000/ppc-floatbitintbf.c: Likewise. * config/rs6000/ppc-floatbitinthf.c: Likewise. Diff: --- libgcc/config/rs6000/convert-16bit-fp-fix | 3 + libgcc/config/rs6000/ppc-fixbfbitint.c | 128 ------------------------------ libgcc/config/rs6000/ppc-fixhfbitint.c | 127 ----------------------------- libgcc/config/rs6000/ppc-floatbitintbf.c | 102 ------------------------ libgcc/config/rs6000/ppc-floatbitinthf.c | 102 ------------------------ libgcc/config/rs6000/t-float16 | 12 +-- 6 files changed, 9 insertions(+), 465 deletions(-) diff --git a/libgcc/config/rs6000/convert-16bit-fp-fix b/libgcc/config/rs6000/convert-16bit-fp-fix index 5417c3694b1f..5390cbe49bd3 100755 --- a/libgcc/config/rs6000/convert-16bit-fp-fix +++ b/libgcc/config/rs6000/convert-16bit-fp-fix @@ -145,6 +145,9 @@ foreach $line (@func) { if ($line =~ /^__(fix|fixuns)([bh]f)([sdt]i)/) { $line = "__${1}${2}${3}_gpr (unsigned short us)"; + } elsif ($line =~ /^__(fix|fixuns)([bh]f)bitint/) { + $line =~ s/${u_letter}Ftype a/unsigned short us/; + # Add conversion from unsigned short } elsif ($line =~ /FP_INIT_EXCEPTIONS/) { print " ${u_letter}Ftype a;\n"; diff --git a/libgcc/config/rs6000/ppc-fixbfbitint.c b/libgcc/config/rs6000/ppc-fixbfbitint.c deleted file mode 100644 index 3271912dc260..000000000000 --- a/libgcc/config/rs6000/ppc-fixbfbitint.c +++ /dev/null @@ -1,128 +0,0 @@ -/* Software floating-point emulation. - Convert IEEE single to signed or unsigned _BitInt. - - Copyright (C) 2023 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. - -Under Section 7 of GPL version 3, you are granted additional -permissions described in the GCC Runtime Library Exception, version -3.1, as published by the Free Software Foundation. - -You should have received a copy of the GNU General Public License and -a copy of the GCC Runtime Library Exception along with this program; -see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -<http://www.gnu.org/licenses/>. - -This is a clone of softfp/fixsfbit.c - -We provide 2 conversions, one that passes the BFtype in a floating point -register and the other returns 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" -#include "bitint.h" - -#ifdef __BITINT_MAXWIDTH__ -/* Silence declaration without prototype warning. */ -extern void __fixbfbitint (UBILtype *, SItype, BFtype); -extern void __fixbfbitint_gpr (UBILtype *, SItype, unsigned short); - -/* BFtype is passed in FPR registers. */ -void -__fixbfbitint (UBILtype *r, SItype rprec, BFtype a) -{ - FP_DECL_EX; - FP_DECL_B (A); - USItype arprec = rprec < 0 ? -rprec : rprec; - USItype rn = ((USItype) arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE; - USItype rv; - USItype rsize = arprec > SI_BITS ? SI_BITS : arprec; - USItype rsigned = rprec < 0; - USItype ovf = 0; - USItype shift = 0; - - FP_INIT_EXCEPTIONS; - FP_UNPACK_RAW_B (A, a); - if (arprec > SI_BITS) - { - if (A_e < _FP_EXPBIAS_B || (A_s && !rsigned)) - ovf = 1; - else if (A_e >= (_FP_EXPMAX_B < _FP_EXPBIAS_B + arprec - ? _FP_EXPMAX_B - : _FP_EXPBIAS_B + arprec - rsigned)) - { - ovf = 1; - if (A_s - && A_e == _FP_EXPBIAS_B + arprec - 1 - && A_e < _FP_EXPMAX_B) - A_e -= arprec - SI_BITS; - } - else if (A_e >= _FP_EXPBIAS_B + SI_BITS - rsigned) - { - shift = A_e - (_FP_EXPBIAS_B + SI_BITS - rsigned - 1); - A_e -= shift; - } - } - FP_TO_INT_B (rv, A, rsize, rsigned); - FP_HANDLE_EXCEPTIONS; - FP_TO_BITINT (r, rn, arprec, shift, rv, rsize, rsigned, ovf, SI); -} - -/* BFtype is passed in GPR registers. */ -void -__fixbfbitint_gpr (UBILtype *r, SItype rprec, unsigned short us) -{ - FP_DECL_EX; - FP_DECL_B (A); - USItype arprec = rprec < 0 ? -rprec : rprec; - USItype rn = ((USItype) arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE; - USItype rv; - USItype rsize = arprec > SI_BITS ? SI_BITS : arprec; - USItype rsigned = rprec < 0; - USItype ovf = 0; - USItype shift = 0; - BFtype a; - union ushort_bf u; - - u.us = us; - a = u.bf; - - FP_INIT_EXCEPTIONS; - FP_UNPACK_RAW_B (A, a); - if (arprec > SI_BITS) - { - if (A_e < _FP_EXPBIAS_B || (A_s && !rsigned)) - ovf = 1; - else if (A_e >= (_FP_EXPMAX_B < _FP_EXPBIAS_B + arprec - ? _FP_EXPMAX_B - : _FP_EXPBIAS_B + arprec - rsigned)) - { - ovf = 1; - if (A_s - && A_e == _FP_EXPBIAS_B + arprec - 1 - && A_e < _FP_EXPMAX_B) - A_e -= arprec - SI_BITS; - } - else if (A_e >= _FP_EXPBIAS_B + SI_BITS - rsigned) - { - shift = A_e - (_FP_EXPBIAS_B + SI_BITS - rsigned - 1); - A_e -= shift; - } - } - FP_TO_INT_B (rv, A, rsize, rsigned); - FP_HANDLE_EXCEPTIONS; - FP_TO_BITINT (r, rn, arprec, shift, rv, rsize, rsigned, ovf, SI); -} -#endif diff --git a/libgcc/config/rs6000/ppc-fixhfbitint.c b/libgcc/config/rs6000/ppc-fixhfbitint.c deleted file mode 100644 index bb1818ec0695..000000000000 --- a/libgcc/config/rs6000/ppc-fixhfbitint.c +++ /dev/null @@ -1,127 +0,0 @@ -/* Software floating-point emulation. - Convert IEEE single to signed or unsigned _BitInt. - - Copyright (C) 2023 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. - -Under Section 7 of GPL version 3, you are granted additional -permissions described in the GCC Runtime Library Exception, version -3.1, as published by the Free Software Foundation. - -You should have received a copy of the GNU General Public License and -a copy of the GCC Runtime Library Exception along with this program; -see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -<http://www.gnu.org/licenses/>. - -This is a clone of softfp/fixsfbit.c - -We provide 2 conversions, one that passes the HFtype in a floating point -register and the other returns 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" -#include "bitint.h" - -#ifdef __BITINT_MAXWIDTH__ -extern void __fixhfbitint (UBILtype *, SItype, HFtype); -extern void __fixhfbitint_gpr (UBILtype *, SItype, unsigned short); - -/* HFtype is passed in FPR registers. */ -void -__fixhfbitint (UBILtype *r, SItype rprec, HFtype a) -{ - FP_DECL_EX; - FP_DECL_H (A); - USItype arprec = rprec < 0 ? -rprec : rprec; - USItype rn = ((USItype) arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE; - USItype rv; - USItype rsize = arprec > SI_BITS ? SI_BITS : arprec; - USItype rsigned = rprec < 0; - USItype ovf = 0; - USItype shift = 0; - - FP_INIT_EXCEPTIONS; - FP_UNPACK_RAW_H (A, a); - if (arprec > SI_BITS) - { - if (A_e < _FP_EXPBIAS_H || (A_s && !rsigned)) - ovf = 1; - else if (A_e >= (_FP_EXPMAX_H < _FP_EXPBIAS_H + arprec - ? _FP_EXPMAX_H - : _FP_EXPBIAS_H + arprec - rsigned)) - { - ovf = 1; - if (A_s - && A_e == _FP_EXPBIAS_H + arprec - 1 - && A_e < _FP_EXPMAX_H) - A_e -= arprec - SI_BITS; - } - else if (A_e >= _FP_EXPBIAS_H + SI_BITS - rsigned) - { - shift = A_e - (_FP_EXPBIAS_H + SI_BITS - rsigned - 1); - A_e -= shift; - } - } - FP_TO_INT_H (rv, A, rsize, rsigned); - FP_HANDLE_EXCEPTIONS; - FP_TO_BITINT (r, rn, arprec, shift, rv, rsize, rsigned, ovf, SI); -} - -/* HFtype is passed in GPR registers. */ -void -__fixhfbitint_gpr (UBILtype *r, SItype rprec, unsigned short us) -{ - FP_DECL_EX; - FP_DECL_H (A); - USItype arprec = rprec < 0 ? -rprec : rprec; - USItype rn = ((USItype) arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE; - USItype rv; - USItype rsize = arprec > SI_BITS ? SI_BITS : arprec; - USItype rsigned = rprec < 0; - USItype ovf = 0; - USItype shift = 0; - HFtype a; - union ushort_hf u; - - u.us = us; - a = u.hf; - - FP_INIT_EXCEPTIONS; - FP_UNPACK_RAW_H (A, a); - if (arprec > SI_BITS) - { - if (A_e < _FP_EXPBIAS_H || (A_s && !rsigned)) - ovf = 1; - else if (A_e >= (_FP_EXPMAX_H < _FP_EXPBIAS_H + arprec - ? _FP_EXPMAX_H - : _FP_EXPBIAS_H + arprec - rsigned)) - { - ovf = 1; - if (A_s - && A_e == _FP_EXPBIAS_H + arprec - 1 - && A_e < _FP_EXPMAX_H) - A_e -= arprec - SI_BITS; - } - else if (A_e >= _FP_EXPBIAS_H + SI_BITS - rsigned) - { - shift = A_e - (_FP_EXPBIAS_H + SI_BITS - rsigned - 1); - A_e -= shift; - } - } - FP_TO_INT_H (rv, A, rsize, rsigned); - FP_HANDLE_EXCEPTIONS; - FP_TO_BITINT (r, rn, arprec, shift, rv, rsize, rsigned, ovf, SI); -} -#endif diff --git a/libgcc/config/rs6000/ppc-floatbitintbf.c b/libgcc/config/rs6000/ppc-floatbitintbf.c deleted file mode 100644 index bc3be1ed8886..000000000000 --- a/libgcc/config/rs6000/ppc-floatbitintbf.c +++ /dev/null @@ -1,102 +0,0 @@ -/* Software floating-point emulation. - Convert a _BitInt to bfloat16. - - Copyright (C) 2023 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. - -Under Section 7 of GPL version 3, you are granted additional -permissions described in the GCC Runtime Library Exception, version -3.1, as published by the Free Software Foundation. - -You should have received a copy of the GNU General Public License and -a copy of the GCC Runtime Library Exception along with this program; -see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -<http://www.gnu.org/licenses/>. - -This is a clone of softfp/floatbitintbf.c. - -We provide 2 conversions, one that returns the BFtype in a floating point -register and the other returns 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" -#include "bitint.h" - -#ifdef __BITINT_MAXWIDTH__ - -/* Silence declaration without prototype warning. */ -extern BFtype __floatbitintbf (const UBILtype *, SItype); -extern unsigned short __floatbitintbf_gpr (const UBILtype *, SItype); - -/* BFtype returned in FPRs. */ -BFtype -__floatbitintbf (const UBILtype *i, SItype iprec) -{ - SItype iv; - USItype shift = 0; - FP_DECL_EX; - FP_DECL_B (A); - BFtype a; - - FP_FROM_BITINT (i, iprec, iv, shift, SI); - FP_INIT_ROUNDMODE; - FP_FROM_INT_B (A, iv, SI_BITS, USItype); - if (shift) - { - A_e += shift; - if (A_e >= _FP_EXPMAX_B) - { - /* Exponent too big; overflow to infinity. */ - _FP_OVERFLOW_SEMIRAW (B, 1, A); - _FP_PACK_SEMIRAW (B, 1, A); - } - } - FP_PACK_RAW_B (a, A); - FP_HANDLE_EXCEPTIONS; - - return a; -} - -/* BFtype returned in GPRs. */ -unsigned short -__floatbitintbf_gpr (const UBILtype *i, SItype iprec) -{ - SItype iv; - USItype shift = 0; - FP_DECL_EX; - FP_DECL_B (A); - BFtype a; - union ushort_bf u; - - FP_FROM_BITINT (i, iprec, iv, shift, SI); - FP_INIT_ROUNDMODE; - FP_FROM_INT_B (A, iv, SI_BITS, USItype); - if (shift) - { - A_e += shift; - if (A_e >= _FP_EXPMAX_B) - { - /* Exponent too big; overflow to infinity. */ - _FP_OVERFLOW_SEMIRAW (B, 1, A); - _FP_PACK_SEMIRAW (B, 1, A); - } - } - FP_PACK_RAW_B (a, A); - FP_HANDLE_EXCEPTIONS; - - u.bf = a; - return u.us; -} -#endif diff --git a/libgcc/config/rs6000/ppc-floatbitinthf.c b/libgcc/config/rs6000/ppc-floatbitinthf.c deleted file mode 100644 index f92376994fb6..000000000000 --- a/libgcc/config/rs6000/ppc-floatbitinthf.c +++ /dev/null @@ -1,102 +0,0 @@ -/* Software floating-point emulation. - Convert a _BitInt to IEEE half. - - Copyright (C) 2023 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. - -Under Section 7 of GPL version 3, you are granted additional -permissions described in the GCC Runtime Library Exception, version -3.1, as published by the Free Software Foundation. - -You should have received a copy of the GNU General Public License and -a copy of the GCC Runtime Library Exception along with this program; -see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -<http://www.gnu.org/licenses/>. - -This is a clone of softfp/floatbitinthf.c. - -We provide 2 conversions, one that returns the BFtype in a floating point -register and the other returns 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 "half.h" -#include "bitint.h" - -#ifdef __BITINT_MAXWIDTH__ - -/* Silence declaration without prototype warning. */ -extern HFtype __floatbitinthf (const UBILtype *, SItype); -extern unsigned short __floatbitinthf_gpr (const UBILtype *, SItype); - -/* HFtype returned in FPRs. */ -HFtype -__floatbitinthf (const UBILtype *i, SItype iprec) -{ - SItype iv; - USItype shift = 0; - FP_DECL_EX; - FP_DECL_H (A); - HFtype a; - - FP_FROM_BITINT (i, iprec, iv, shift, SI); - FP_INIT_ROUNDMODE; - FP_FROM_INT_H (A, iv, SI_BITS, USItype); - if (shift) - { - A_e += shift; - if (A_e >= _FP_EXPMAX_H) - { - /* Exponent too big; overflow to infinity. */ - _FP_OVERFLOW_SEMIRAW (H, 1, A); - _FP_PACK_SEMIRAW (H, 1, A); - } - } - FP_PACK_RAW_H (a, A); - FP_HANDLE_EXCEPTIONS; - - return a; -} - -/* HFtype returned in FPRs. */ -unsigned short -__floatbitinthf_gpr (const UBILtype *i, SItype iprec) -{ - SItype iv; - USItype shift = 0; - FP_DECL_EX; - FP_DECL_H (A); - HFtype a; - union ushort_hf u; - - FP_FROM_BITINT (i, iprec, iv, shift, SI); - FP_INIT_ROUNDMODE; - FP_FROM_INT_H (A, iv, SI_BITS, USItype); - if (shift) - { - A_e += shift; - if (A_e >= _FP_EXPMAX_H) - { - /* Exponent too big; overflow to infinity. */ - _FP_OVERFLOW_SEMIRAW (H, 1, A); - _FP_PACK_SEMIRAW (H, 1, A); - } - } - FP_PACK_RAW_H (a, A); - FP_HANDLE_EXCEPTIONS; - - u.hf = a; - return u.us; -} -#endif diff --git a/libgcc/config/rs6000/t-float16 b/libgcc/config/rs6000/t-float16 index ac4b52fe08aa..a471ac3b4824 100644 --- a/libgcc/config/rs6000/t-float16 +++ b/libgcc/config/rs6000/t-float16 @@ -2,7 +2,7 @@ PERL := perl # _Float16 library support, source files in soft-ftp fp16_funcs = extendhf-sfdf2 truncsfdf-hf2 \ - ppc-eqhf2 ppc-floatbitinthf ppc-fixhfbitint + ppc-eqhf2 fp16_src = $(addprefix $(srcdir)/config/rs6000/,$(addsuffix .c,$(fp16_funcs))) fp16_obj = $(addsuffix $(objext),$(fp16_funcs)) @@ -15,7 +15,7 @@ $(fp16_obj) : INTERNAL_CFLAGS += $(FP16_CFLAGS) # __bf16 library support, source files in config/rs6000 bfp16_funcs = extendbf-sfdf2 truncsfdf-bf2 \ - ppc-eqbf2 ppc-floatbitintbf ppc-fixbfbitint + ppc-eqbf2 bfp16_src = $(addprefix $(srcdir)/config/rs6000/,$(addsuffix .c,$(bfp16_funcs))) bfp16_obj = $(addsuffix $(objext),$(bfp16_funcs)) @@ -43,7 +43,7 @@ float16_fix_script = $(srcdir)/config/rs6000/convert-16bit-fp-fix float16_float_script = $(srcdir)/config/rs6000/convert-16bit-fp-float # Convert fix* functions for _Float16 -fp16x_fix_funcs = fixhfti fixhfdi fixhfsi +fp16x_fix_funcs = fixhfti fixhfdi fixhfsi fixhfbitint fp16x_fix_src = $(addprefix $(float16_prefix),$(addsuffix .c,$(fp16x_fix_funcs))) fp16x_fix_obj = $(addprefix $(float16_prefix),$(addsuffix $(objext),$(fp16x_fix_funcs))) @@ -59,7 +59,7 @@ fp16x_fixuns_dep = $(float16_fixuns_orig) \ $(float16_fix_script) \ $(srcdir)/config/rs6000/t-float16 -fp16x_float_funcs = floattihf floatdihf floatsihf +fp16x_float_funcs = floattihf floatdihf floatsihf floatbitinthf fp16x_float_src = $(addprefloat $(float16_prefloat),$(addsuffloat .c,$(fp16x_float_funcs))) fp16x_float_obj = $(addprefloat $(float16_prefloat),$(addsuffloat $(objext),$(fp16x_float_funcs))) @@ -99,7 +99,7 @@ $(fp16x_floatun_src) : $(fp16x_floatun_dep) $(fp16x_all_obj) : INTERNAL_CFLAGS += $(FP16_CFLAGS) # Convert fix* functions for __bf12 -bfp16x_fix_funcs = fixbfti fixbfdi fixbfsi +bfp16x_fix_funcs = fixbfti fixbfdi fixbfsi fixbfbitint bfp16x_fix_src = $(addprefix $(float16_prefix),$(addsuffix .c,$(bfp16x_fix_funcs))) bfp16x_fix_obj = $(addprefix $(float16_prefix),$(addsuffix $(objext),$(bfp16x_fix_funcs))) @@ -115,7 +115,7 @@ bfp16x_fixuns_dep = $(float16_fixuns_orig) \ $(float16_fix_script) \ $(srcdir)/config/rs6000/t-float16 -bfp16x_float_funcs = floattibf floatdibf floatsibf +bfp16x_float_funcs = floattibf floatdibf floatsibf floatbitinthf bfp16x_float_src = $(addprefloat $(float16_prefloat),$(addsuffloat .c,$(bfp16x_float_funcs))) bfp16x_float_obj = $(addprefloat $(float16_prefloat),$(addsuffloat $(objext),$(bfp16x_float_funcs)))
