aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2016-08-22 12:57:39 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2016-08-22 12:57:39 +0100
commit6dc198e3a58a7acc5874f8912180f0a8ec8554c6 (patch)
treea1de76d3b52462d1b6ade9d5d4e0f6f207b974cf /gcc/builtins.c
parent7ff4e41a19132c87c9ef6f0bd2ca809a6c2172a8 (diff)
downloadgcc-6dc198e3a58a7acc5874f8912180f0a8ec8554c6.zip
gcc-6dc198e3a58a7acc5874f8912180f0a8ec8554c6.tar.gz
gcc-6dc198e3a58a7acc5874f8912180f0a8ec8554c6.tar.bz2
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
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index abc934b..cf0cfc7 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -5875,6 +5875,7 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode,
switch (fcode)
{
CASE_FLT_FN (BUILT_IN_FABS):
+ CASE_FLT_FN_FLOATN_NX (BUILT_IN_FABS):
case BUILT_IN_FABSD32:
case BUILT_IN_FABSD64:
case BUILT_IN_FABSD128:
@@ -5884,6 +5885,7 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode,
break;
CASE_FLT_FN (BUILT_IN_COPYSIGN):
+ CASE_FLT_FN_FLOATN_NX (BUILT_IN_COPYSIGN):
target = expand_builtin_copysign (exp, target, subtarget);
if (target)
return target;
@@ -8208,12 +8210,14 @@ fold_builtin_0 (location_t loc, tree fndecl)
return fold_builtin_LINE (loc, type);
CASE_FLT_FN (BUILT_IN_INF):
+ CASE_FLT_FN_FLOATN_NX (BUILT_IN_INF):
case BUILT_IN_INFD32:
case BUILT_IN_INFD64:
case BUILT_IN_INFD128:
return fold_builtin_inf (loc, type, true);
CASE_FLT_FN (BUILT_IN_HUGE_VAL):
+ CASE_FLT_FN_FLOATN_NX (BUILT_IN_HUGE_VAL):
return fold_builtin_inf (loc, type, false);
case BUILT_IN_CLASSIFY_TYPE:
@@ -8262,6 +8266,7 @@ fold_builtin_1 (location_t loc, tree fndecl, tree arg0)
return fold_builtin_strlen (loc, type, arg0);
CASE_FLT_FN (BUILT_IN_FABS):
+ CASE_FLT_FN_FLOATN_NX (BUILT_IN_FABS):
case BUILT_IN_FABSD32:
case BUILT_IN_FABSD64:
case BUILT_IN_FABSD128: