aboutsummaryrefslogtreecommitdiff
path: root/libgcc/soft-fp/floatuntidd.c
AgeCommit message (Collapse)AuthorFilesLines
2025-05-27libgcc: Add DPD support + fix big-endian support of _BitInt <-> dfp conversionsJakub Jelinek1-1/+5
The following patch fixes FAIL: gcc.dg/dfp/bitint-1.c (test for excess errors) FAIL: gcc.dg/dfp/bitint-2.c (test for excess errors) FAIL: gcc.dg/dfp/bitint-3.c (test for excess errors) FAIL: gcc.dg/dfp/bitint-4.c (test for excess errors) FAIL: gcc.dg/dfp/bitint-5.c (test for excess errors) FAIL: gcc.dg/dfp/bitint-6.c (test for excess errors) FAIL: gcc.dg/dfp/bitint-8.c (test for excess errors) FAIL: gcc.dg/dfp/int128-1.c (test for excess errors) FAIL: gcc.dg/dfp/int128-2.c (test for excess errors) FAIL: gcc.dg/dfp/int128-4.c (test for excess errors) on s390x-linux (with the 3 not yet posted patches). The patch does multiple things: 1) the routines were written for the DFP BID (binary integer decimal) format which is used on all arches but powerpc*/s390* (those use DPD - densely packed decimal format); as most of the code is actually the same for both BID and DPD formats, I haven't copied the sources + slightly modified them, but added the DPD support directly, + renaming of the exported symbols from __bid_* prefixed to __dpd_* prefixed that GCC expects on the DPD targets 2) while testing that I've found some big-endian issues in the existing support 3) testing also revealed that in some cases __builtin_clzll (~msb) was called with msb set to all ones, so invoking UB; apparently on aarch64 and x86 we were lucky and got some value that happened to work well, but that wasn't the case on s390x For 1), the patch uses two ~ 2KB tables to speed up the decoding/encoding. I haven't found such tables in what is added into libgcc.a, though they are in libdecnumber/bid/bid2dpd_dpd2bid.h, but there they are just huge and next to other huge tables - there is d2b which is like __dpd_d2bbitint in the patch but it uses 64-bit entries rather than 16-bit, then there is d2b2 with 64-bit entries like in d2b all multiplied by 1000, then d2b3 similarly multiplied by 1000000, then d2b4 similarly multiplied by 1000000000, then d2b5 similarly multiplied by 1000000000000ULL and d2b6 similarly multipled by 1000000000000000ULL. Arguably it can save some of the multiplications, but on the other side accesses memory which is unlikely in the caches, and the 2048 bytes in the patch vs. 24 times more for d2b is IMHO significant. For b2d, libdecnumber/bid/bid2dpd_dpd2bid.h has again b2d table like __dpd_b2dbitint in the patch, except that it has 64-bit entries rather than 16-bit (this time 1000 entries), but then has b2d2 which has the same entries shifted left by 10, then b2d3 shifted left by 20, b2d4 shifted left by 30 and b2d5 shifted left by 40. I can understand for d2b paying memory cost to speed up multiplications, but don't understand paying extra 4 * 8 * 1000 bytes (+ 6 * 1000 bytes for b2d not using ushort) just to avoid shifts. 2025-05-27 Jakub Jelinek <jakub@redhat.com> * config/t-softfp (softfp_bid_list): Don't guard with $(enable_decimal_float) == bid. * soft-fp/bitint.h (__bid_pow10bitint): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_pow10bitint. (__dpd_d2bbitint, __dpd_b2dbitint): Declare. * soft-fp/bitintpow10.c (__dpd_d2bbitint, __dpd_b2dbitint): New variables. * soft-fp/fixsdbitint.c (__bid_fixsdbitint): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixsdbitint. Add DPD support. Fix big-endian support. * soft-fp/fixddbitint.c (__bid_fixddbitint): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixddbitint. Add DPD support. Fix big-endian support. * soft-fp/fixtdbitint.c (__bid_fixtdbitint): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixtdbitint. Add DPD support. Fix big-endian support. * soft-fp/fixsdti.c (__bid_fixsdbitint): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixsdbitint. (__bid_fixsdti): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixsdti. * soft-fp/fixddti.c (__bid_fixddbitint): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixddbitint. (__bid_fixddti): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixddti. * soft-fp/fixtdti.c (__bid_fixtdbitint): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixtdbitint. (__bid_fixtdti): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixtdti. * soft-fp/fixunssdti.c (__bid_fixsdbitint): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixsdbitint. (__bid_fixunssdti): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixunssdti. * soft-fp/fixunsddti.c (__bid_fixddbitint): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixddbitint. (__bid_fixunsddti): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixunsddti. * soft-fp/fixunstdti.c (__bid_fixtdbitint): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixtdbitint. (__bid_fixunstdti): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_fixunstdti. * soft-fp/floatbitintsd.c (__bid_floatbitintsd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatbitintsd. Add DPD support. Avoid calling __builtin_clzll with 0 argument. Fix big-endian support. * soft-fp/floatbitintdd.c (__bid_floatbitintdd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatbitintdd. Add DPD support. Avoid calling __builtin_clzll with 0 argument. Fix big-endian support. * soft-fp/floatbitinttd.c (__bid_floatbitinttd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatbitinttd. Add DPD support. Avoid calling __builtin_clzll with 0 argument. Fix big-endian support. * soft-fp/floattisd.c (__bid_floatbitintsd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatbitintsd. (__bid_floattisd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floattisd. * soft-fp/floattidd.c (__bid_floatbitintdd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatbitintdd. (__bid_floattidd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floattidd. * soft-fp/floattitd.c (__bid_floatbitinttd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatbitinttd. (__bid_floattitd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floattitd. * soft-fp/floatuntisd.c (__bid_floatbitintsd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatbitintsd. (__bid_floatuntisd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatuntisd. * soft-fp/floatuntidd.c (__bid_floatbitintdd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatbitintdd. (__bid_floatuntidd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatuntidd. * soft-fp/floatuntitd.c (__bid_floatbitinttd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatbitinttd. (__bid_floatuntitd): For !defined(ENABLE_DECIMAL_BID_FORMAT) redefine to __dpd_floatuntitd.
2023-11-09libgcc: Add {unsigned ,}__int128 <-> _Decimal{32,64,128} conversion support ↵Jakub Jelinek1-0/+53
[PR65833] The following patch adds the missing {unsigned ,}__int128 <-> _Decimal{32,64,128} conversion support into libgcc.a on top of the _BitInt support (doing it without that would be larger amount of code and I hope all the targets which support __int128 will eventually support _BitInt, after all it is a required part of C23) and because it is in libgcc.a only, it doesn't hurt that much if it is added for some architectures only in GCC 15. Initially I thought about doing this on the compiler side, but doing it on the library side seems to be easier and more -Os friendly. The tests currently require bitint effective target, that can be removed when all the int128 targets support bitint. 2023-11-09 Jakub Jelinek <jakub@redhat.com> PR libgcc/65833 libgcc/ * config/t-softfp (softfp_bid_list): Add {U,}TItype <-> _Decimal{32,64,128} conversions. * soft-fp/floattisd.c: New file. * soft-fp/floattidd.c: New file. * soft-fp/floattitd.c: New file. * soft-fp/floatuntisd.c: New file. * soft-fp/floatuntidd.c: New file. * soft-fp/floatuntitd.c: New file. * soft-fp/fixsdti.c: New file. * soft-fp/fixddti.c: New file. * soft-fp/fixtdti.c: New file. * soft-fp/fixunssdti.c: New file. * soft-fp/fixunsddti.c: New file. * soft-fp/fixunstdti.c: New file. gcc/testsuite/ * gcc.dg/dfp/int128-1.c: New test. * gcc.dg/dfp/int128-2.c: New test. * gcc.dg/dfp/int128-3.c: New test. * gcc.dg/dfp/int128-4.c: New test.