aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/builtins.def3
-rw-r--r--gcc/doc/extend.texi12
-rw-r--r--gcc/doc/sourcebuild.texi5
-rw-r--r--gcc/fold-const-call.c3
-rw-r--r--gcc/testsuite/gcc.dg/dfp/builtin-snan-1.c23
-rw-r--r--gcc/testsuite/gcc.dg/dfp/builtin-snan-2.c44
-rw-r--r--gcc/testsuite/lib/target-supports.exp38
7 files changed, 128 insertions, 0 deletions
diff --git a/gcc/builtins.def b/gcc/builtins.def
index 68f2da6..b4494c7 100644
--- a/gcc/builtins.def
+++ b/gcc/builtins.def
@@ -518,6 +518,9 @@ DEF_GCC_BUILTIN (BUILT_IN_NANSF, "nansf", BT_FN_FLOAT_CONST_STRING, ATTR_
DEF_GCC_BUILTIN (BUILT_IN_NANSL, "nansl", BT_FN_LONGDOUBLE_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL)
DEF_GCC_FLOATN_NX_BUILTINS (BUILT_IN_NANS, "nans", NAN_TYPE, ATTR_CONST_NOTHROW_NONNULL)
#undef NAN_TYPE
+DEF_GCC_BUILTIN (BUILT_IN_NANSD32, "nansd32", BT_FN_DFLOAT32_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL)
+DEF_GCC_BUILTIN (BUILT_IN_NANSD64, "nansd64", BT_FN_DFLOAT64_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL)
+DEF_GCC_BUILTIN (BUILT_IN_NANSD128, "nansd128", BT_FN_DFLOAT128_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL)
DEF_C99_BUILTIN (BUILT_IN_NEARBYINT, "nearbyint", BT_FN_DOUBLE_DOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
DEF_C99_BUILTIN (BUILT_IN_NEARBYINTF, "nearbyintf", BT_FN_FLOAT_FLOAT, ATTR_CONST_NOTHROW_LEAF_LIST)
DEF_C99_BUILTIN (BUILT_IN_NEARBYINTL, "nearbyintl", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_CONST_NOTHROW_LEAF_LIST)
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 7a6ecce..e6a9bdf 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -13865,6 +13865,18 @@ to be a signaling NaN@. The @code{nans} function is proposed by
@uref{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n965.htm,,WG14 N965}.
@end deftypefn
+@deftypefn {Built-in Function} _Decimal32 __builtin_nansd32 (const char *str)
+Similar to @code{__builtin_nans}, except the return type is @code{_Decimal32}.
+@end deftypefn
+
+@deftypefn {Built-in Function} _Decimal64 __builtin_nansd64 (const char *str)
+Similar to @code{__builtin_nans}, except the return type is @code{_Decimal64}.
+@end deftypefn
+
+@deftypefn {Built-in Function} _Decimal128 __builtin_nansd128 (const char *str)
+Similar to @code{__builtin_nans}, except the return type is @code{_Decimal128}.
+@end deftypefn
+
@deftypefn {Built-in Function} float __builtin_nansf (const char *str)
Similar to @code{__builtin_nans}, except the return type is @code{float}.
@end deftypefn
diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index 49316a5..b3c5e53 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2356,6 +2356,11 @@ Target provides @file{fenv.h} include file.
Target supports @file{fenv.h} with all the standard IEEE exceptions
and floating-point exceptions are raised by arithmetic operations.
+@item fenv_exceptions_dfp
+Target supports @file{fenv.h} with all the standard IEEE exceptions
+and floating-point exceptions are raised by arithmetic operations for
+decimal floating point.
+
@item fileio
Target offers such file I/O library functions as @code{fopen},
@code{fclose}, @code{tmpnam}, and @code{remove}. This is a link-time
diff --git a/gcc/fold-const-call.c b/gcc/fold-const-call.c
index 11ed47d..3548fab 100644
--- a/gcc/fold-const-call.c
+++ b/gcc/fold-const-call.c
@@ -1300,6 +1300,9 @@ fold_const_call (combined_fn fn, tree type, tree arg)
CASE_CFN_NANS:
CASE_FLT_FN_FLOATN_NX (CFN_BUILT_IN_NANS):
+ case CFN_BUILT_IN_NANSD32:
+ case CFN_BUILT_IN_NANSD64:
+ case CFN_BUILT_IN_NANSD128:
return fold_const_builtin_nan (type, arg, false);
case CFN_REDUC_PLUS:
diff --git a/gcc/testsuite/gcc.dg/dfp/builtin-snan-1.c b/gcc/testsuite/gcc.dg/dfp/builtin-snan-1.c
new file mode 100644
index 0000000..49a32c8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/dfp/builtin-snan-1.c
@@ -0,0 +1,23 @@
+/* Test __builtin_nansd* functions. Test not requiring runtime
+ exceptions support. */
+/* { dg-do run } */
+/* { dg-options "" } */
+
+volatile _Decimal32 d32 = __builtin_nansd32 ("");
+volatile _Decimal64 d64 = __builtin_nansd64 ("");
+volatile _Decimal128 d128 = __builtin_nansd128 ("");
+
+extern void abort (void);
+extern void exit (int);
+
+int
+main (void)
+{
+ if (!__builtin_isnan (d32))
+ abort ();
+ if (!__builtin_isnan (d64))
+ abort ();
+ if (!__builtin_isnan (d128))
+ abort ();
+ exit (0);
+}
diff --git a/gcc/testsuite/gcc.dg/dfp/builtin-snan-2.c b/gcc/testsuite/gcc.dg/dfp/builtin-snan-2.c
new file mode 100644
index 0000000..248481b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/dfp/builtin-snan-2.c
@@ -0,0 +1,44 @@
+/* Test __builtin_nansd* functions. Test requiring runtime exceptions
+ support. */
+/* { dg-do run } */
+/* { dg-require-effective-target fenv_exceptions_dfp } */
+/* { dg-options "" } */
+
+#include <fenv.h>
+
+volatile _Decimal32 d32 = __builtin_nansd32 ("");
+volatile _Decimal64 d64 = __builtin_nansd64 ("");
+volatile _Decimal128 d128 = __builtin_nansd128 ("");
+
+extern void abort (void);
+extern void exit (int);
+
+int
+main (void)
+{
+ feclearexcept (FE_ALL_EXCEPT);
+ d32 += d32;
+ if (!fetestexcept (FE_INVALID))
+ abort ();
+ feclearexcept (FE_ALL_EXCEPT);
+ d32 += d32;
+ if (fetestexcept (FE_INVALID))
+ abort ();
+ feclearexcept (FE_ALL_EXCEPT);
+ d64 += d64;
+ if (!fetestexcept (FE_INVALID))
+ abort ();
+ feclearexcept (FE_ALL_EXCEPT);
+ d64 += d64;
+ if (fetestexcept (FE_INVALID))
+ abort ();
+ feclearexcept (FE_ALL_EXCEPT);
+ d128 += d128;
+ if (!fetestexcept (FE_INVALID))
+ abort ();
+ feclearexcept (FE_ALL_EXCEPT);
+ d128 += d128;
+ if (fetestexcept (FE_INVALID))
+ abort ();
+ exit (0);
+}
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 08e96e1..60ebbb3 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -9693,6 +9693,44 @@ proc check_effective_target_fenv_exceptions {} {
} [add_options_for_ieee "-std=gnu99"]]
}
+# Return 1 if <fenv.h> is available with all the standard IEEE
+# exceptions and floating-point exceptions are raised by arithmetic
+# operations for decimal floating point. (If the target requires
+# special options for "inexact" exceptions, those need to be specified
+# in the testcases.)
+
+proc check_effective_target_fenv_exceptions_dfp {} {
+ return [check_runtime fenv_exceptions_dfp {
+ #include <fenv.h>
+ #include <stdlib.h>
+ #ifndef FE_DIVBYZERO
+ # error Missing FE_DIVBYZERO
+ #endif
+ #ifndef FE_INEXACT
+ # error Missing FE_INEXACT
+ #endif
+ #ifndef FE_INVALID
+ # error Missing FE_INVALID
+ #endif
+ #ifndef FE_OVERFLOW
+ # error Missing FE_OVERFLOW
+ #endif
+ #ifndef FE_UNDERFLOW
+ # error Missing FE_UNDERFLOW
+ #endif
+ volatile _Decimal64 a = 0.0DD, r;
+ int
+ main (void)
+ {
+ r = a / a;
+ if (fetestexcept (FE_INVALID))
+ exit (0);
+ else
+ abort ();
+ }
+ } [add_options_for_ieee "-std=gnu99"]]
+}
+
# Return 1 if -fexceptions is supported.
proc check_effective_target_exceptions {} {