Add minimal _FloatN, _FloatNx built-in functions.
authorJoseph Myers <joseph@codesourcery.com>
Mon, 22 Aug 2016 11:57:39 +0000 (12:57 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Mon, 22 Aug 2016 11:57:39 +0000 (12:57 +0100)
commit6dc198e3a58a7acc5874f8912180f0a8ec8554c6
treea1de76d3b52462d1b6ade9d5d4e0f6f207b974cf
parent7ff4e41a19132c87c9ef6f0bd2ca809a6c2172a8
Add minimal _FloatN, _FloatNx built-in functions.

This patch adds a minimal set of built-in functions for the new
_FloatN and _FloatNx types.

The functions added are __builtin_fabs*, __builtin_copysign*,
__builtin_huge_val*, __builtin_inf*, __builtin_nan* and
__builtin_nans* (where * = fN or fNx).  That is, 42 new entries are
added to the enum of built-in functions and the associated array of
decls, where not all of them are actually supported on any one target.

These functions are believed to be sufficient for libgcc (complex
multiplication and division use __builtin_huge_val*,
__builtin_copysign* and __builtin_fabs*) and for glibc (which also
depends on complex multiplication from libgcc, as well as using such
functions itself).  The basic target-independent support for folding /
expanding calls to these built-in functions is wired up, so those for
constants can be used in static initializers, and the fabs and
copysign built-ins can always be expanded to bit-manipulation inline
(for any format setting signbit_ro and signbit_rw, which covers all
formats supported for _FloatN and _FloatNx), although insn patterns
for fabs (abs<mode>2) and copysign (copysign<mode>3) will be used when
available and may result in more optimal code.

The complex multiplication and division functions in libgcc rely on
predefined macros (defined with -fbuilding-libgcc) to say what the
built-in function suffixes to use with a particular mode are.  This
patch updates that code accordingly, where previously it involved a
hack supposing that machine-specific suffixes for constants were also
suffixes for built-in functions.

As with the main _FloatN / _FloatNx patch, this patch does not update
code dealing only with optimizations that currently has cases only
covering float, double and long double, though some such cases are
straightforward and may be covered in a followup patch.

The functions are defined with DEF_GCC_BUILTIN, so calls to the TS
18661-3 functions such as fabsf128 and copysignf128, without the
__builtin_, will not be optimized.  As noted in the original _FloatN /
_FloatNx patch submission, in principle the bulk of the libm functions
that have built-in versions should have those versions extended to
cover the new types, but that would require more consideration of the
effects of increasing the size of the enum and initializing many more
functions at startup.

I don't know whether target-specific built-in functions can readily be
made into aliases for target-independent functions, but if they can,
it would make sense to do so for the x86, ia64 and rs6000 *q functions
corresponding to these, so that they can benefit from the
architecture-independent folding logic and from any optimizations
enabled for these functions in future, and so that less
target-specific code is needed to support them.

Bootstrapped with no regressions on x86_64-pc-linux-gnu.

gcc:
* tree.h (CASE_FLT_FN_FLOATN_NX, float16_type_node)
(float32_type_node, float64_type_node, float32x_type_node)
(float128x_type_node): New macros.
* builtin-types.def (BT_FLOAT16, BT_FLOAT32, BT_FLOAT64)
(BT_FLOAT128, BT_FLOAT32X, BT_FLOAT64X, BT_FLOAT128X)
(BT_FN_FLOAT16, BT_FN_FLOAT32, BT_FN_FLOAT64, BT_FN_FLOAT128)
(BT_FN_FLOAT32X, BT_FN_FLOAT64X, BT_FN_FLOAT128X)
(BT_FN_FLOAT16_FLOAT16, BT_FN_FLOAT32_FLOAT32)
(BT_FN_FLOAT64_FLOAT64, BT_FN_FLOAT128_FLOAT128)
(BT_FN_FLOAT32X_FLOAT32X, BT_FN_FLOAT64X_FLOAT64X)
(BT_FN_FLOAT128X_FLOAT128X, BT_FN_FLOAT16_CONST_STRING)
(BT_FN_FLOAT32_CONST_STRING, BT_FN_FLOAT64_CONST_STRING)
(BT_FN_FLOAT128_CONST_STRING, BT_FN_FLOAT32X_CONST_STRING)
(BT_FN_FLOAT64X_CONST_STRING, BT_FN_FLOAT128X_CONST_STRING)
(BT_FN_FLOAT16_FLOAT16_FLOAT16, BT_FN_FLOAT32_FLOAT32_FLOAT32)
(BT_FN_FLOAT64_FLOAT64_FLOAT64, BT_FN_FLOAT128_FLOAT128_FLOAT128)
(BT_FN_FLOAT32X_FLOAT32X_FLOAT32X)
(BT_FN_FLOAT64X_FLOAT64X_FLOAT64X)
(BT_FN_FLOAT128X_FLOAT128X_FLOAT128X): New type definitions.
* builtins.def (DEF_GCC_FLOATN_NX_BUILTINS): New macro.
(copysign, fabs, huge_val, inf, nan, nans): Use it.
* builtins.c (expand_builtin): Use CASE_FLT_FN_FLOATN_NX for fabs
and copysign.
(fold_builtin_0): Use CASE_FLT_FN_FLOATN_NX for inf and huge_val.
(fold_builtin_1): Use CASE_FLT_FN_FLOATN_NX for fabs.
* doc/extend.texi (Other Builtins): Document these built-in
functions.
* fold-const-call.c (fold_const_call): Use CASE_FLT_FN_FLOATN_NX
for nan and nans.

gcc/c-family:
* c-family/c-cppbuiltin.c (c_cpp_builtins): Check _FloatN and
_FloatNx types for suffixes for built-in functions.

gcc/testsuite:
* gcc.dg/torture/float128-builtin.c,
gcc.dg/torture/float128-ieee-nan.c,
gcc.dg/torture/float128x-builtin.c,
gcc.dg/torture/float128x-nan.c, gcc.dg/torture/float16-builtin.c,
gcc.dg/torture/float16-nan.c, gcc.dg/torture/float32-builtin.c,
gcc.dg/torture/float32-nan.c, gcc.dg/torture/float32x-builtin.c,
gcc.dg/torture/float32x-nan.c, gcc.dg/torture/float64-builtin.c,
gcc.dg/torture/float64-nan.c, gcc.dg/torture/float64x-builtin.c,
gcc.dg/torture/float64x-nan.c, gcc.dg/torture/floatn-builtin.h,
gcc.dg/torture/floatn-nan.h: New tests.

From-SVN: r239658
26 files changed:
gcc/ChangeLog
gcc/builtin-types.def
gcc/builtins.c
gcc/builtins.def
gcc/c-family/ChangeLog
gcc/c-family/c-cppbuiltin.c
gcc/doc/extend.texi
gcc/fold-const-call.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/float128-builtin.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float128-ieee-nan.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float128x-builtin.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float128x-nan.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float16-builtin.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float16-nan.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float32-builtin.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float32-nan.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float32x-builtin.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float32x-nan.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float64-builtin.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float64-nan.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float64x-builtin.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/float64x-nan.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/floatn-builtin.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/floatn-nan.h [new file with mode: 0644]
gcc/tree.h