aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg
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/testsuite/gcc.dg
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/testsuite/gcc.dg')
-rw-r--r--gcc/testsuite/gcc.dg/torture/float128-builtin.c9
-rw-r--r--gcc/testsuite/gcc.dg/torture/float128-ieee-nan.c10
-rw-r--r--gcc/testsuite/gcc.dg/torture/float128x-builtin.c9
-rw-r--r--gcc/testsuite/gcc.dg/torture/float128x-nan.c10
-rw-r--r--gcc/testsuite/gcc.dg/torture/float16-builtin.c9
-rw-r--r--gcc/testsuite/gcc.dg/torture/float16-nan.c10
-rw-r--r--gcc/testsuite/gcc.dg/torture/float32-builtin.c9
-rw-r--r--gcc/testsuite/gcc.dg/torture/float32-nan.c10
-rw-r--r--gcc/testsuite/gcc.dg/torture/float32x-builtin.c9
-rw-r--r--gcc/testsuite/gcc.dg/torture/float32x-nan.c10
-rw-r--r--gcc/testsuite/gcc.dg/torture/float64-builtin.c9
-rw-r--r--gcc/testsuite/gcc.dg/torture/float64-nan.c10
-rw-r--r--gcc/testsuite/gcc.dg/torture/float64x-builtin.c9
-rw-r--r--gcc/testsuite/gcc.dg/torture/float64x-nan.c10
-rw-r--r--gcc/testsuite/gcc.dg/torture/floatn-builtin.h64
-rw-r--r--gcc/testsuite/gcc.dg/torture/floatn-nan.h39
16 files changed, 236 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/torture/float128-builtin.c b/gcc/testsuite/gcc.dg/torture/float128-builtin.c
new file mode 100644
index 0000000..e4a50ce
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float128-builtin.c
@@ -0,0 +1,9 @@
+/* Test _Float128 built-in functions. */
+/* { dg-do run } */
+/* { dg-options "" } */
+/* { dg-add-options float128 } */
+/* { dg-require-effective-target float128_runtime } */
+
+#define WIDTH 128
+#define EXT 0
+#include "floatn-builtin.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float128-ieee-nan.c b/gcc/testsuite/gcc.dg/torture/float128-ieee-nan.c
new file mode 100644
index 0000000..5dfbff9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float128-ieee-nan.c
@@ -0,0 +1,10 @@
+/* Test _Float128 NaNs. */
+/* { dg-do run } */
+/* { dg-options "-fsignaling-nans" } */
+/* { dg-add-options float128 } */
+/* { dg-require-effective-target float128_runtime } */
+/* { dg-require-effective-target fenv_exceptions } */
+
+#define WIDTH 128
+#define EXT 0
+#include "floatn-nan.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float128x-builtin.c b/gcc/testsuite/gcc.dg/torture/float128x-builtin.c
new file mode 100644
index 0000000..2e6bbaf
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float128x-builtin.c
@@ -0,0 +1,9 @@
+/* Test _Float128x built-in functions. */
+/* { dg-do run } */
+/* { dg-options "" } */
+/* { dg-add-options float128x } */
+/* { dg-require-effective-target float128x_runtime } */
+
+#define WIDTH 128
+#define EXT 1
+#include "floatn-builtin.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float128x-nan.c b/gcc/testsuite/gcc.dg/torture/float128x-nan.c
new file mode 100644
index 0000000..ad0052f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float128x-nan.c
@@ -0,0 +1,10 @@
+/* Test _Float128x NaNs. */
+/* { dg-do run } */
+/* { dg-options "-fsignaling-nans" } */
+/* { dg-add-options float128x } */
+/* { dg-require-effective-target float128x_runtime } */
+/* { dg-require-effective-target fenv_exceptions } */
+
+#define WIDTH 128
+#define EXT 1
+#include "floatn-nan.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float16-builtin.c b/gcc/testsuite/gcc.dg/torture/float16-builtin.c
new file mode 100644
index 0000000..43f9b19
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float16-builtin.c
@@ -0,0 +1,9 @@
+/* Test _Float16 built-in functions. */
+/* { dg-do run } */
+/* { dg-options "" } */
+/* { dg-add-options float16 } */
+/* { dg-require-effective-target float16_runtime } */
+
+#define WIDTH 16
+#define EXT 0
+#include "floatn-builtin.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float16-nan.c b/gcc/testsuite/gcc.dg/torture/float16-nan.c
new file mode 100644
index 0000000..859f30c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float16-nan.c
@@ -0,0 +1,10 @@
+/* Test _Float16 NaNs. */
+/* { dg-do run } */
+/* { dg-options "-fsignaling-nans" } */
+/* { dg-add-options float16 } */
+/* { dg-require-effective-target float16_runtime } */
+/* { dg-require-effective-target fenv_exceptions } */
+
+#define WIDTH 16
+#define EXT 0
+#include "floatn-nan.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float32-builtin.c b/gcc/testsuite/gcc.dg/torture/float32-builtin.c
new file mode 100644
index 0000000..fc14ad1e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float32-builtin.c
@@ -0,0 +1,9 @@
+/* Test _Float32 built-in functions. */
+/* { dg-do run } */
+/* { dg-options "" } */
+/* { dg-add-options float32 } */
+/* { dg-require-effective-target float32_runtime } */
+
+#define WIDTH 32
+#define EXT 0
+#include "floatn-builtin.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float32-nan.c b/gcc/testsuite/gcc.dg/torture/float32-nan.c
new file mode 100644
index 0000000..c46b388
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float32-nan.c
@@ -0,0 +1,10 @@
+/* Test _Float32 NaNs. */
+/* { dg-do run } */
+/* { dg-options "-fsignaling-nans" } */
+/* { dg-add-options float32 } */
+/* { dg-require-effective-target float32_runtime } */
+/* { dg-require-effective-target fenv_exceptions } */
+
+#define WIDTH 32
+#define EXT 0
+#include "floatn-nan.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float32x-builtin.c b/gcc/testsuite/gcc.dg/torture/float32x-builtin.c
new file mode 100644
index 0000000..3a5c2d0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float32x-builtin.c
@@ -0,0 +1,9 @@
+/* Test _Float32x built-in functions. */
+/* { dg-do run } */
+/* { dg-options "" } */
+/* { dg-add-options float32x } */
+/* { dg-require-effective-target float32x_runtime } */
+
+#define WIDTH 32
+#define EXT 1
+#include "floatn-builtin.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float32x-nan.c b/gcc/testsuite/gcc.dg/torture/float32x-nan.c
new file mode 100644
index 0000000..770499d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float32x-nan.c
@@ -0,0 +1,10 @@
+/* Test _Float32x NaNs. */
+/* { dg-do run } */
+/* { dg-options "-fsignaling-nans" } */
+/* { dg-add-options float32x } */
+/* { dg-require-effective-target float32x_runtime } */
+/* { dg-require-effective-target fenv_exceptions } */
+
+#define WIDTH 32
+#define EXT 1
+#include "floatn-nan.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float64-builtin.c b/gcc/testsuite/gcc.dg/torture/float64-builtin.c
new file mode 100644
index 0000000..ff3cb29
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float64-builtin.c
@@ -0,0 +1,9 @@
+/* Test _Float64 built-in functions. */
+/* { dg-do run } */
+/* { dg-options "" } */
+/* { dg-add-options float64 } */
+/* { dg-require-effective-target float64_runtime } */
+
+#define WIDTH 64
+#define EXT 0
+#include "floatn-builtin.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float64-nan.c b/gcc/testsuite/gcc.dg/torture/float64-nan.c
new file mode 100644
index 0000000..5f1a2e8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float64-nan.c
@@ -0,0 +1,10 @@
+/* Test _Float64 NaNs. */
+/* { dg-do run } */
+/* { dg-options "-fsignaling-nans" } */
+/* { dg-add-options float64 } */
+/* { dg-require-effective-target float64_runtime } */
+/* { dg-require-effective-target fenv_exceptions } */
+
+#define WIDTH 64
+#define EXT 0
+#include "floatn-nan.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float64x-builtin.c b/gcc/testsuite/gcc.dg/torture/float64x-builtin.c
new file mode 100644
index 0000000..2f95e8a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float64x-builtin.c
@@ -0,0 +1,9 @@
+/* Test _Float64x built-in functions. */
+/* { dg-do run } */
+/* { dg-options "" } */
+/* { dg-add-options float64x } */
+/* { dg-require-effective-target float64x_runtime } */
+
+#define WIDTH 64
+#define EXT 1
+#include "floatn-builtin.h"
diff --git a/gcc/testsuite/gcc.dg/torture/float64x-nan.c b/gcc/testsuite/gcc.dg/torture/float64x-nan.c
new file mode 100644
index 0000000..3d6496d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/float64x-nan.c
@@ -0,0 +1,10 @@
+/* Test _Float64x NaNs. */
+/* { dg-do run } */
+/* { dg-options "-fsignaling-nans" } */
+/* { dg-add-options float64x } */
+/* { dg-require-effective-target float64x_runtime } */
+/* { dg-require-effective-target fenv_exceptions } */
+
+#define WIDTH 64
+#define EXT 1
+#include "floatn-nan.h"
diff --git a/gcc/testsuite/gcc.dg/torture/floatn-builtin.h b/gcc/testsuite/gcc.dg/torture/floatn-builtin.h
new file mode 100644
index 0000000..c562812
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/floatn-builtin.h
@@ -0,0 +1,64 @@
+/* Tests for _FloatN / _FloatNx types: compile and execution tests for
+ built-in functions. Before including this file, define WIDTH as
+ the value N; define EXT to 1 for _FloatNx and 0 for _FloatN. */
+
+#define CONCATX(X, Y) X ## Y
+#define CONCAT(X, Y) CONCATX (X, Y)
+#define CONCAT3(X, Y, Z) CONCAT (CONCAT (X, Y), Z)
+#define CONCAT4(W, X, Y, Z) CONCAT (CONCAT (CONCAT (W, X), Y), Z)
+
+#if EXT
+# define TYPE CONCAT3 (_Float, WIDTH, x)
+# define CST(C) CONCAT4 (C, f, WIDTH, x)
+# define FN(F) CONCAT4 (F, f, WIDTH, x)
+#else
+# define TYPE CONCAT (_Float, WIDTH)
+# define CST(C) CONCAT3 (C, f, WIDTH)
+# define FN(F) CONCAT3 (F, f, WIDTH)
+#endif
+
+extern void exit (int);
+extern void abort (void);
+
+extern TYPE test_type;
+extern __typeof (FN (__builtin_inf) ()) test_type;
+extern __typeof (FN (__builtin_huge_val) ()) test_type;
+extern __typeof (FN (__builtin_nan) ("")) test_type;
+extern __typeof (FN (__builtin_nans) ("")) test_type;
+extern __typeof (FN (__builtin_fabs) (0)) test_type;
+extern __typeof (FN (__builtin_copysign) (0, 0)) test_type;
+
+volatile TYPE inf_cst = FN (__builtin_inf) ();
+volatile TYPE huge_val_cst = FN (__builtin_huge_val) ();
+volatile TYPE nan_cst = FN (__builtin_nan) ("");
+volatile TYPE nans_cst = FN (__builtin_nans) ("");
+volatile TYPE neg0 = -CST (0.0), neg1 = -CST (1.0), one = 1.0;
+
+int
+main (void)
+{
+ volatile TYPE r;
+ if (!__builtin_isinf (inf_cst))
+ abort ();
+ if (!__builtin_isinf (huge_val_cst))
+ abort ();
+ if (inf_cst != huge_val_cst)
+ abort ();
+ if (!__builtin_isnan (nan_cst))
+ abort ();
+ if (!__builtin_isnan (nans_cst))
+ abort ();
+ r = FN (__builtin_fabs) (neg1);
+ if (r != CST (1.0))
+ abort ();
+ r = FN (__builtin_copysign) (one, neg0);
+ if (r != neg1)
+ abort ();
+ r = FN (__builtin_copysign) (inf_cst, neg1);
+ if (r != -huge_val_cst)
+ abort ();
+ r = FN (__builtin_copysign) (-inf_cst, one);
+ if (r != huge_val_cst)
+ abort ();
+ exit (0);
+}
diff --git a/gcc/testsuite/gcc.dg/torture/floatn-nan.h b/gcc/testsuite/gcc.dg/torture/floatn-nan.h
new file mode 100644
index 0000000..89d2e2e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/floatn-nan.h
@@ -0,0 +1,39 @@
+/* Tests for _FloatN / _FloatNx types: compile and execution tests for
+ NaNs. Before including this file, define WIDTH as the value N;
+ define EXT to 1 for _FloatNx and 0 for _FloatN. */
+
+#define CONCATX(X, Y) X ## Y
+#define CONCAT(X, Y) CONCATX (X, Y)
+#define CONCAT3(X, Y, Z) CONCAT (CONCAT (X, Y), Z)
+#define CONCAT4(W, X, Y, Z) CONCAT (CONCAT (CONCAT (W, X), Y), Z)
+
+#if EXT
+# define TYPE CONCAT3 (_Float, WIDTH, x)
+# define CST(C) CONCAT4 (C, f, WIDTH, x)
+# define FN(F) CONCAT4 (F, f, WIDTH, x)
+#else
+# define TYPE CONCAT (_Float, WIDTH)
+# define CST(C) CONCAT3 (C, f, WIDTH)
+# define FN(F) CONCAT3 (F, f, WIDTH)
+#endif
+
+#include <fenv.h>
+
+extern void exit (int);
+extern void abort (void);
+
+volatile TYPE nan_cst = FN (__builtin_nan) ("");
+volatile TYPE nans_cst = FN (__builtin_nans) ("");
+
+int
+main (void)
+{
+ volatile TYPE r;
+ r = nan_cst + nan_cst;
+ if (fetestexcept (FE_INVALID))
+ abort ();
+ r = nans_cst + nans_cst;
+ if (!fetestexcept (FE_INVALID))
+ abort ();
+ exit (0);
+}