GCC modified for the FreeChainXenon project
![]() On Fri, Oct 28, 2022 at 12:52:44PM -0400, Patrick Palka wrote: > > The following patch on top of > > https://gcc.gnu.org/pipermail/libstdc++/2022-October/054849.html > > adds std::{,b}float16_t support for std::to_chars. > > When precision is specified (or for std::bfloat16_t for hex mode even if not), > > I believe we can just use the std::to_chars float (when float is mode > > compatible with std::float32_t) overloads, both formats are proper subsets > > of std::float32_t. > > Unfortunately when precision is not specified and we are supposed to emit > > shortest string, the std::{,b}float16_t strings are usually much shorter. > > E.g. 1.e7p-14f16 shortest fixed representation is > > 0.0001161 and shortest scientific representation is > > 1.161e-04 while 1.e7p-14f32 (same number promoted to std::float32_t) > > 0.00011610985 and > > 1.1610985e-04. > > Similarly for 1.38p-112bf16, > > 0.000000000000000000000000000000000235 > > 2.35e-34 vs. 1.38p-112f32 > > 0.00000000000000000000000000000000023472271 > > 2.3472271e-34 > > For std::float16_t there are differences even in the shortest hex, say: > > 0.01p-14 vs. 1p-22 > > but only for denormal std::float16_t values (where all std::float16_t > > denormals converted to std::float32_t are normal), __FLT16_MIN__ and > > everything larger in absolute value than that is the same. Unless > > that is a bug and we should try to discover shorter representations > > even for denormals... > > IIRC for hex formatting of denormals I opted to be consistent with how > glibc printf formats them, instead of outputting the truly shortest > form. > > I wouldn't be against using the float32 overloads even for shortest hex > formatting of float16. The output is shorter but equivalent so it > shouldn't cause any problems. The following patch changes the behavior of the shortest hex denormals, such that they are printed like normals (so for has_implicit_leading_bit with 1p-149 instead of 0.000002p-126 etc., otherwise (Intel extended) with the leading digit before dot being [89abcdef]). I think for all the supported format it is never longer, it can be equal length e.g. for 0.fffffep-126 vs. 1.fffffcp-127 but fortunately no largest subnormal in any format has the unbiased exponent like -9, -99, -999, -9999 because then it would be longer and often it is shorter, sometimes much shorter. For the cases with precision it keeps the handling as is. While for !has_implicit_leading_bit we for normals or with this patch even denormals have really shortest representation, for other formats we sometimes do not, but this patch doesn't deal with that (we always use 1.NNN while we could use 1.NNN up to f.NNN and by that shortening by the last hexit if the last hexit doesn't have least significant bit set and unbiased exponent is not -9, -99, -999 or -9999. 2022-11-02 Jakub Jelinek <jakub@redhat.com> * src/c++17/floating_to_chars.cc (__floating_to_chars_hex): Drop const from unbiased_exponent. Canonicalize denormals such that they have the leading bit set by shifting effective mantissa up and decreasing unbiased_exponent. (__floating_to_chars_shortest): Don't instantiate __floating_to_chars_hex for float16_t either and use float instead. * testsuite/20_util/to_chars/float.cc (float_to_chars_test_cases): Adjust testcases for shortest hex denormals. * testsuite/20_util/to_chars/double.cc (double_to_chars_test_cases): Likewise. |
||
---|---|---|
c++tools | ||
config | ||
contrib | ||
fixincludes | ||
gcc | ||
gnattools | ||
gotools | ||
include | ||
INSTALL | ||
intl | ||
libada | ||
libatomic | ||
libbacktrace | ||
libcc1 | ||
libcody | ||
libcpp | ||
libdecnumber | ||
libffi | ||
libgcc | ||
libgfortran | ||
libgo | ||
libgomp | ||
libiberty | ||
libitm | ||
libobjc | ||
liboffloadmic | ||
libphobos | ||
libquadmath | ||
libsanitizer | ||
libssp | ||
libstdc++-v3 | ||
libvtv | ||
lto-plugin | ||
maintainer-scripts | ||
zlib | ||
.dir-locals.el | ||
.gitattributes | ||
.gitignore | ||
ABOUT-NLS | ||
ar-lib | ||
ChangeLog | ||
ChangeLog.jit | ||
ChangeLog.tree-ssa | ||
compile | ||
config-ml.in | ||
config.guess | ||
config.rpath | ||
config.sub | ||
configure | ||
configure.ac | ||
COPYING | ||
COPYING.LIB | ||
COPYING.RUNTIME | ||
COPYING3 | ||
COPYING3.LIB | ||
depcomp | ||
install-sh | ||
libtool-ldflags | ||
libtool.m4 | ||
ltgcc.m4 | ||
ltmain.sh | ||
ltoptions.m4 | ||
ltsugar.m4 | ||
ltversion.m4 | ||
lt~obsolete.m4 | ||
MAINTAINERS | ||
Makefile.def | ||
Makefile.in | ||
Makefile.tpl | ||
missing | ||
mkdep | ||
mkinstalldirs | ||
move-if-change | ||
multilib.am | ||
README | ||
symlink-tree | ||
test-driver | ||
ylwrap |
This directory contains the GNU Compiler Collection (GCC). The GNU Compiler Collection is free software. See the files whose names start with COPYING for copying permission. The manuals, and some of the runtime libraries, are under different terms; see the individual source files for details. The directory INSTALL contains copies of the installation information as HTML and plain text. The source of this information is gcc/doc/install.texi. The installation information includes details of what is included in the GCC sources and what files GCC installs. See the file gcc/doc/gcc.texi (together with other files that it includes) for usage and porting information. An online readable version of the manual is in the files gcc/doc/gcc.info*. See http://gcc.gnu.org/bugs/ for how to report bugs usefully. Copyright years on GCC source files may be listed using range notation, e.g., 1987-2012, indicating that every year in the range, inclusive, is a copyrightable year that could otherwise be listed individually.