Re: [PATCH 9/12] libgcc _BitInt support [PR102989]
On Fri, Sep 01, 2023 at 09:48:22PM +, Joseph Myers wrote: > This patch is OK with these fixes. Thanks, here is an updated patch, thanks for catching the _Decimal128 bug. Will post testsuite additions/adjustment patch as follow-up on Monday. 2023-09-02 Jakub Jelinek PR c/102989 libgcc/ * config/aarch64/t-softfp (softfp_extras): Use += rather than :=. * config/i386/64/t-softfp (softfp_extras): Likewise. * config/i386/libgcc-glibc.ver (GCC_14.0.0): Export _BitInt support routines. * config/i386/t-softfp (softfp_extras): Add fixxfbitint and bf, hf and xf mode floatbitint. (CFLAGS-floatbitintbf.c, CFLAGS-floatbitinthf.c): Add -msse2. * config/riscv/t-softfp32 (softfp_extras): Use += rather than :=. * config/rs6000/t-e500v1-fp (softfp_extras): Likewise. * config/rs6000/t-e500v2-fp (softfp_extras): Likewise. * config/t-softfp (softfp_floatbitint_funcs): New. (softfp_bid_list): New. (softfp_func_list): Add sf and df mode from and to _BitInt libcalls. (softfp_bid_file_list): New. (LIB2ADD_ST): Add $(softfp_bid_file_list). * config/t-softfp-sfdftf (softfp_extras): Add fixtfbitint and floatbitinttf. * config/t-softfp-tf (softfp_extras): Likewise. * libgcc2.c (bitint_reduce_prec): New inline function. (BITINT_INC, BITINT_END): Define. (bitint_mul_1, bitint_addmul_1): New helper functions. (__mulbitint3): New function. (bitint_negate, bitint_submul_1): New helper functions. (__divmodbitint4): New function. * libgcc2.h (LIBGCC2_UNITS_PER_WORD): When building _BitInt support libcalls, redefine depending on __LIBGCC_BITINT_LIMB_WIDTH__. (__mulbitint3, __divmodbitint4): Declare. * libgcc-std.ver.in (GCC_14.0.0): Export _BitInt support routines. * Makefile.in (lib2funcs): Add _mulbitint3. (LIB2_DIVMOD_FUNCS): Add _divmodbitint4. * soft-fp/bitint.h: New file. * soft-fp/fixdfbitint.c: New file. * soft-fp/fixsfbitint.c: New file. * soft-fp/fixtfbitint.c: New file. * soft-fp/fixxfbitint.c: New file. * soft-fp/floatbitintbf.c: New file. * soft-fp/floatbitintdf.c: New file. * soft-fp/floatbitinthf.c: New file. * soft-fp/floatbitintsf.c: New file. * soft-fp/floatbitinttf.c: New file. * soft-fp/floatbitintxf.c: New file. * soft-fp/op-common.h (_FP_FROM_INT): Add support for rsize up to 4 * _FP_W_TYPE_SIZE rather than just 2 * _FP_W_TYPE_SIZE. * soft-fp/bitintpow10.c: New file. * soft-fp/fixsdbitint.c: New file. * soft-fp/fixddbitint.c: New file. * soft-fp/fixtdbitint.c: New file. * soft-fp/floatbitintsd.c: New file. * soft-fp/floatbitintdd.c: New file. * soft-fp/floatbitinttd.c: New file. --- libgcc/config/aarch64/t-softfp.jj 2023-08-08 15:54:35.737595343 +0200 +++ libgcc/config/aarch64/t-softfp 2023-08-08 16:12:02.346939560 +0200 @@ -3,7 +3,7 @@ softfp_int_modes := si di ti softfp_extensions := sftf dftf hftf bfsf softfp_truncations := tfsf tfdf tfhf tfbf dfbf sfbf hfbf softfp_exclude_libgcc2 := n -softfp_extras := fixhfti fixunshfti floattihf floatuntihf \ +softfp_extras += fixhfti fixunshfti floattihf floatuntihf \ floatdibf floatundibf floattibf floatuntibf TARGET_LIBGCC2_CFLAGS += -Wno-missing-prototypes --- libgcc/config/i386/64/t-softfp.jj 2023-08-08 15:54:35.766594936 +0200 +++ libgcc/config/i386/64/t-softfp 2023-08-08 16:12:02.346939560 +0200 @@ -1,4 +1,4 @@ -softfp_extras := fixhfti fixunshfti floattihf floatuntihf \ +softfp_extras += fixhfti fixunshfti floattihf floatuntihf \ floattibf floatuntibf CFLAGS-fixhfti.c += -msse2 --- libgcc/config/i386/libgcc-glibc.ver.jj 2023-08-08 15:54:35.831594026 +0200 +++ libgcc/config/i386/libgcc-glibc.ver 2023-08-08 16:12:02.347939546 +0200 @@ -226,3 +226,13 @@ GCC_13.0.0 { __truncxfbf2 __trunchfbf2 } + +%inherit GCC_14.0.0 GCC_13.0.0 +GCC_14.0.0 { + __PFX__fixxfbitint + __PFX__fixtfbitint + __PFX__floatbitintbf + __PFX__floatbitinthf + __PFX__floatbitintxf + __PFX__floatbitinttf +} --- libgcc/config/i386/t-softfp.jj 2023-08-08 15:55:09.819118062 +0200 +++ libgcc/config/i386/t-softfp 2023-08-08 16:12:02.347939546 +0200 @@ -10,7 +10,7 @@ softfp_extensions := hfsf hfdf hftf hfxf softfp_truncations := tfhf xfhf dfhf sfhf tfsf dfsf tfdf tfxf \ tfbf xfbf dfbf sfbf hfbf -softfp_extras += eqhf2 +softfp_extras += eqhf2 fixxfbitint $(foreach m,hf bf xf,floatbitint$(m)) CFLAGS-extendhfsf2.c += -msse2 CFLAGS-extendhfdf2.c += -msse2 @@ -28,6 +28,9 @@ CFLAGS-truncxfbf2.c += -msse2 CFLAGS-trunctfbf2.c += -msse2 CFLAGS-trunchfbf2.c += -msse2 +CFLAGS-floatbitintbf.c += -msse2 +CFLAGS-floatbitinthf.c += -msse2 + CFLAGS-eqhf2.c += -msse2 CFLAGS-_divhc3.c += -msse2
Re: [PATCH 9/12] libgcc _BitInt support [PR102989]
On Wed, 9 Aug 2023, Jakub Jelinek via Gcc-patches wrote: > I know that soft-fp is owned by glibc and I think the op-common.h change > should be propagated there, but the bitint stuff is really GCC specific > and IMHO doesn't belong into the glibc copy. The op-common.h change is OK for glibc. Some additional tests I think should be added to the testsuite for floating-point functionality in this patch, that I didn't spot in the testsuite patches - if any of these aren't included initially, there should at least be bugs filed in Bugzilla for the omissions: 1. Test overflowing conversions to integers (including from inf or NaN) raise FE_INVALID. (Note: it's not specified in the standard whether inexact conversions to integers raise FE_INEXACT or not, so testing that seems less important.) 2. Test conversions from integers to floating point raise FE_INEXACT when inexact, together with FE_OVERFLOW when overflowing (while exact conversions don't raise exceptions). 3. Test conversions from integers to floating point respect the rounding mode. 4. Test converting floating-point values in the range (-1.0, 0.0] to both unsigned and signed _BitInt; I didn't see such tests for binary floating types, only for decimal types, and the decimal tests didn't include tests of negative zero itself as the value converted to _BitInt. 5. Test conversions of noncanonical BID zero to integers (these tests would be specific to BID). See below for a bug in this area. For points 2 and 3 above, it's probably appropriate to test only for binary floating point, to avoid any issues with the separate DFP rounding mode and with DFP arithmetic operations not necessarily working correctly with exceptions - but then a bug should be filed in Bugzilla noting the omission of such tests for DFP. For points 1, 2 and 3 above, if the conversions for types such as _BitInt(32) might end up using the same conversions as for types such as int, then tests for such types should probably be omitted (again with a bug filed) given the range of known bugs about exceptions from such operations with types such as int. > +__bid_fixtdbitint (UBILtype *r, SItype rprec, _Decimal128 a) > +{ > + FP_DECL_EX; > + USItype arprec = rprec < 0 ? -rprec : rprec; > + USItype rn = (arprec + BIL_TYPE_SIZE - 1) / BIL_TYPE_SIZE; > + union { _Decimal128 d; UDItype u[2]; } u; > + UDItype mantissahi, mantissalo, t; > + SItype sgn; > + SItype exponent; > + USItype exp_bits, mant_bits; > + UBILtype *pow10v, *resv; > + USItype pow10_limbs, res_limbs, min_limbs, mant_limbs, low_zeros; > + > + FP_INIT_EXCEPTIONS; > + u.d = a; > + mantissahi = u.u[__FLOAT_WORD_ORDER__ != __ORDER_BIG_ENDIAN__]; > + mantissalo = u.u[__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__]; > + t = mantissahi >> 47; > + sgn = (DItype) mantissahi < 0; > + if ((t & (3 << 14)) != (3 << 14)) > +{ > + mantissahi &= UDItype) 1) << 49) - 1); > + exponent = (t >> 2) & 0x3fff; Overflow (thus producing a noncanonical zero) is possible in this case for TDmode. An appropriate test of a noncanonical zero that goes through this case should thus be added to the testsuite. > +} > + else if ((t & (3 << 12)) != (3 << 12)) > +{ > + mantissahi &= UDItype) 1) << 47) - 1); > + mantissahi |= ((UDItype) 1) << 49; > + exponent = t & 0x3fff; > + if (mantissahi > (UDItype) 0x1ed09bead87c0 > + || (mantissahi == (UDItype) 0x1ed09bead87c0 > + && mantissalo > 0x378d8e63)) > + { > + mantissahi = 0; > + mantissalo = 0; > + } And in this case, overflow is guaranteed; the check for the overflow threshold should thus move to the previous case. This patch is OK with these fixes. Note for powerpc architecture maintainers: adding _BitInt support on that architecture will mean, as well as adding support for the conversions to/from DPD (if S/390 doesn't get there first), also adding support for conversions to/from IBM long double. -- Joseph S. Myers jos...@codesourcery.com