C23 Annex H adds <math.h> typedefs long_double_t and _FloatN_t
(originally introduced in TS 18661-3), analogous to float_t and
double_t. Add these typedefs to glibc. (There are no _FloatNx_t
typedefs.)
C23 also slightly changes the rules for how such typedef names should
be defined, compared to the definition in TS 18661-3. In both cases,
<TYPE>_t corresponds to the evaluation format for <TYPE>, as specified
by FLT_EVAL_METHOD (for which <math.h> uses glibc's internal
__GLIBC_FLT_EVAL_METHOD). Specifically, each FLT_EVAL_METHOD value
corresponds to some type U (for example, 64 corresponds to U =
_Float64), and for types with exactly the same set of values as U, TS
18661-3 says expressions with those types are to be evaluated to the
range and precision of type U (so <TYPE>_t is defined to U), whereas
C23 only does that for types whose values are a strict subset of those
of type U (so <TYPE>_t is defined to <TYPE>).
As with other cases where semantics changed between TS 18661 and C23,
this patch only implements the newer version of the semantics
(including adjusting existing definitions of float_t and double_t as
needed). The new semantics are contradictory between the main
standard and Annex H for the case of FLT_EVAL_METHOD == 2 and the
choice of double_t when double and long double have the same values
(the main standard says it's defined as long double in that case,
whereas Annex H would define it as double), which I've raised on the
WG14 reflector (but I think setting FLT_EVAL_METHOD == 2 when double
and long double have the same values is a fairly theoretical
combination of features); for now glibc follows the value in the main
standard in that case.
Note that I think all existing GCC targets supported by glibc only use
values -1, 0, 1, 2 or 16 for FLT_EVAL_METHOD (so most of the header
code is somewhat theoretical, though potentially relevant with other
compilers since the choice of FLT_EVAL_METHOD is only an API choice,
not an ABI one; it can vary with compiler options, and these typedefs
should not be used in ABIs). The testcase (expanded to cover the new
typedefs) is really just repeating the same logic in a second place
(so all it really tests is that __GLIBC_FLT_EVAL_METHOD is consistent
with FLT_EVAL_METHOD).
Tested for x86_64 and x86, and with build-many-glibcs.py.
I used these shell commands:
../glibc/scripts/update-copyrights $PWD/../gnulib/build-aux/update-copyright
(cd ../glibc && git commit -am"[this commit message]")
and then ignored the output, which consisted lines saying "FOO: warning:
copyright statement not found" for each of 7061 files FOO.
I then removed trailing white space from math/tgmath.h,
support/tst-support-open-dev-null-range.c, and
sysdeps/x86_64/multiarch/strlen-vec.S, to work around the following
obscure pre-commit check failure diagnostics from Savannah. I don't
know why I run into these diagnostics whereas others evidently do not.
remote: *** 912-#endif
remote: *** 913:
remote: *** 914-
remote: *** error: lines with trailing whitespace found
...
remote: *** error: sysdeps/unix/sysv/linux/statx_cp.c: trailing lines
I used these shell commands:
../glibc/scripts/update-copyrights $PWD/../gnulib/build-aux/update-copyright
(cd ../glibc && git commit -am"[this commit message]")
and then ignored the output, which consisted lines saying "FOO: warning:
copyright statement not found" for each of 6694 files FOO.
I then removed trailing white space from benchtests/bench-pthread-locks.c
and iconvdata/tst-iconv-big5-hkscs-to-2ucs4.c, to work around this
diagnostic from Savannah:
remote: *** pre-commit check failed ...
remote: *** error: lines with trailing whitespace found
remote: error: hook declined to update refs/heads/master
The default (top-level) version of bits/mathdef.h defines float_t to
double. It is used on ColdFire, MicroBlaze, Nios II and SH3, all of
which define FLT_EVAL_METHOD to 0, so float_t should be float (and C11
requires a certain correspondence between these typedefs and
FLT_EVAL_METHOD values).
I proposed fixing this default in
<https://sourceware.org/ml/libc-alpha/2015-01/msg00499.html>, with no
objections from architecture maintainers, and this patch makes that
fix. As noted in the NEWS entry added, this might affect the ABIs of
non-glibc libraries (ImageMagick has been mentioned in gcc-patches
discussion of the S/390 case - which is unaffected by this patch), but
as noted in my previous message, affected libraries would have
problems with -mfpmath=sse anyway on 32-bit x86.
A (compilation) testcase is added to verify the required
correspondence of typedefs to FLT_EVAL_METHOD values. This test is
built with -fexcess-precision=standard to avoid any issues with GCC 7
on S/390 providing a more accurate FLT_EVAL_METHOD definition in the
default (no excess precision) mode. (This will also be usable to test
a fix for the recently reported bug about these typedefs on x86_64
-mfpmath=387, as architecture-specific tests can be added that
It is entirely possible that the fixed default makes some
architecture-specific versions of bits/mathdef.h semantically
equivalent to the default version and so no longer required. I don't
intend to investigate that separately from the refactoring I proposed
in <https://sourceware.org/ml/libc-alpha/2016-11/msg00745.html>, which
will create as few header variants as possible for each group of
definitions.
Tested (compilation only) with build-many-glibcs.py.
[BZ #20855]
* bits/mathdef.h (float_t): Define to float.
* math/test-flt-eval-method.c: New file.
* math/Makefile (tests): Add test-flt-eval-method.
(CFLAGS-test-flt-eval-method.c): New variable.