https://gcc.gnu.org/g:05ee076a7c326558a31930b825c314b730afc905
commit 05ee076a7c326558a31930b825c314b730afc905 Author: Michael Meissner <[email protected]> Date: Sat Sep 26 17:23:47 2026 -0400 Add ppc-floatbitintbf.c and ppc-floatbitinthf.c 2026-09-26 Michael Meissner <[email protected]> * config/rs6000/ppc-floatbitintbf.c: New file. * config/rs6000/ppc-floatbitinthf.c: Likewise. * config/rs6000/t-float16: Add ppc-floatbitintbf.c and ppc-floatbitinthf.c. Diff: --- libgcc/config/rs6000/ppc-floatbitintbf.c | 102 +++++++++++++++++++++++++++++++ libgcc/config/rs6000/ppc-floatbitinthf.c | 102 +++++++++++++++++++++++++++++++ libgcc/config/rs6000/t-float16 | 38 +++--------- 3 files changed, 212 insertions(+), 30 deletions(-) diff --git a/libgcc/config/rs6000/ppc-floatbitintbf.c b/libgcc/config/rs6000/ppc-floatbitintbf.c new file mode 100644 index 000000000000..bc3be1ed8886 --- /dev/null +++ b/libgcc/config/rs6000/ppc-floatbitintbf.c @@ -0,0 +1,102 @@ +/* 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 new file mode 100644 index 000000000000..f92376994fb6 --- /dev/null +++ b/libgcc/config/rs6000/ppc-floatbitinthf.c @@ -0,0 +1,102 @@ +/* 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 c7222bc5b1dd..b6d342e25312 100644 --- a/libgcc/config/rs6000/t-float16 +++ b/libgcc/config/rs6000/t-float16 @@ -1,24 +1,13 @@ # _Float16 library support, source files in soft-ftp -fp16_funcs_1 = floatbitinthf - -fp16_src_1 = $(addprefix $(srcdir)/soft-fp/,$(addsuffix .c,$(fp16_funcs_1))) -fp16_obj_1 = $(addsuffix $(objext),$(fp16_funcs_1)) - -# _Float16 library support, source files in config/rs6000 -fp16_funcs_2 = extendhf-sfdf2 truncsfdf-hf2 \ +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 - -fp16_src_2 = $(addprefix $(srcdir)/config/rs6000/,$(addsuffix .c,$(fp16_funcs_2))) -fp16_obj_2 = $(addsuffix $(objext),$(fp16_funcs_2)) + ppc-eqhf2 ppc-floatbitinthf -# _Float16 combined library support -fp16_funcs = $(fp16_funcs_1) $(fp16_funcs_2) -fp16_src = $(fp16_src_1) $(fp16_src_2) -fp16_obj = $(fp16_obj_1) $(fp16_obj_2) +fp16_src = $(addprefix $(srcdir)/config/rs6000/,$(addsuffix .c,$(fp16_funcs))) +fp16_obj = $(addsuffix $(objext),$(fp16_funcs)) FP16_CFLAGS = -mfloat16 -Wno-psabi \ -I$(srcdir)/soft-fp \ @@ -26,27 +15,16 @@ FP16_CFLAGS = -mfloat16 -Wno-psabi \ $(fp16_obj) : INTERNAL_CFLAGS += $(FP16_CFLAGS) -# __bf16 library support, source files in soft-ftp -bfp16_funcs_1 = floatbitintbf - -bfp16_src_1 = $(addprefix $(srcdir)/soft-fp/,$(addsuffix .c,$(bfp16_funcs_1))) -bfp16_obj_1 = $(addsuffix $(objext),$(bfp16_funcs_1)) - # __bf16 library support, source files in config/rs6000 -bfp16_funcs_2 = extendbf-sfdf2 truncsfdf-bf2 \ +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 - -bfp16_src_2 = $(addprefix $(srcdir)/config/rs6000/,$(addsuffix .c,$(bfp16_funcs_2))) -bfp16_obj_2 = $(addsuffix $(objext),$(bfp16_funcs_2)) + ppc-eqbf2 ppc-floatbitintbf -# __bf16 combined library support -bfp16_funcs = $(bfp16_funcs_1) $(bfp16_funcs_2) -bfp16_src = $(bfp16_src_1) $(bfp16_src_2) -bfp16_obj = $(bfp16_obj_1) $(bfp16_obj_2) +bfp16_src = $(addprefix $(srcdir)/config/rs6000/,$(addsuffix .c,$(bfp16_funcs))) +bfp16_obj = $(addsuffix $(objext),$(bfp16_funcs)) $(bfp16_obj) : INTERNAL_CFLAGS += $(FP16_CFLAGS)
