* float.h: C2x decimal signaling NaN macros
@ 2020-11-05 23:21 Joseph Myers
2020-11-06 17:53 ` Jeff Law
0 siblings, 1 reply; 2+ messages in thread
From: Joseph Myers @ 2020-11-05 23:21 UTC (permalink / raw)
To: gcc-patches
C2x adds macros for decimal floating-point signaling NaNs to
<float.h>. Add these macros to GCC's <float.h> implementation.
Note that the current C2x draft has these under incorrect names
D32_SNAN, D64_SNAN, D128_SNAN. The intent was to change the naming
convention to be consistent with other <float.h> macros when they were
moved to <float.h>, so DEC32_SNAN, DEC64_SNAN, DEC128_NAN, which this
patch uses (as does the current draft integration of TS 18661-3 as an
Annex to C2x, for its _Decimal* and _Decimal*x types).
This patch is relative to a tree with
<https://gcc.gnu.org/pipermail/gcc-patches/2020-October/557136.html>
and
<https://gcc.gnu.org/pipermail/gcc-patches/2020-November/558126.html>
(both pending review) applied.
Bootstrapped with no regressions for x86_64-pc-linux-gnu. OK to commit?
gcc/
2020-11-05 Joseph Myers <joseph@codesourcery.com>
* ginclude/float.h (DEC32_SNAN, DEC64_SNAN, DEC128_SNAN): New C2x
macros.
gcc/testsuite/
2020-11-05 Joseph Myers <joseph@codesourcery.com>
* gcc.dg/dfp/c2x-float-dfp-7.c, gcc.dg/dfp/c2x-float-dfp-8.c: New
tests.
* gcc.dg/c2x-float-no-dfp-3.c: Also check that DEC32_SNAN,
DEC64_SNAN and DEC128_SNAN are not defined.
diff --git a/gcc/ginclude/float.h b/gcc/ginclude/float.h
index 77446995515..0fa00461230 100644
--- a/gcc/ginclude/float.h
+++ b/gcc/ginclude/float.h
@@ -601,6 +601,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#undef DEC_NAN
#define DEC_NAN (__builtin_nand32 (""))
+/* Signaling NaN in each decimal floating-point type. */
+#undef DEC32_SNAN
+#define DEC32_SNAN (__builtin_nansd32 (""))
+#undef DEC64_SNAN
+#define DEC64_SNAN (__builtin_nansd64 (""))
+#undef DEC128_SNAN
+#define DEC128_SNAN (__builtin_nansd128 (""))
+
#endif /* C2X */
#endif /* __DEC32_MANT_DIG__ */
diff --git a/gcc/testsuite/gcc.dg/c2x-float-no-dfp-3.c b/gcc/testsuite/gcc.dg/c2x-float-no-dfp-3.c
index d8a239c787e..aa790c8e21d 100644
--- a/gcc/testsuite/gcc.dg/c2x-float-no-dfp-3.c
+++ b/gcc/testsuite/gcc.dg/c2x-float-no-dfp-3.c
@@ -12,3 +12,15 @@
#ifdef DEC_NAN
# error "DEC_NAN defined"
#endif
+
+#ifdef DEC32_SNAN
+# error "DEC32_SNAN defined"
+#endif
+
+#ifdef DEC64_SNAN
+# error "DEC64_SNAN defined"
+#endif
+
+#ifdef DEC128_SNAN
+# error "DEC128_SNAN defined"
+#endif
diff --git a/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-7.c b/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-7.c
new file mode 100644
index 00000000000..dec6b500656
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-7.c
@@ -0,0 +1,45 @@
+/* Test DEC*_SNAN macros defined in <float.h> with DFP support. */
+/* { dg-do run } */
+/* { dg-options "-std=c2x" } */
+
+#include <float.h>
+
+#ifndef DEC32_SNAN
+# error "DEC32_SNAN not defined"
+#endif
+
+#ifndef DEC64_SNAN
+# error "DEC64_SNAN not defined"
+#endif
+
+#ifndef DEC128_SNAN
+# error "DEC128_SNAN not defined"
+#endif
+
+volatile _Decimal32 d32 = DEC32_SNAN;
+volatile _Decimal64 d64 = DEC64_SNAN;
+volatile _Decimal128 d128 = DEC128_SNAN;
+
+extern void abort (void);
+extern void exit (int);
+
+int
+main (void)
+{
+ (void) _Generic (DEC32_SNAN, _Decimal32 : 0);
+ if (!__builtin_isnan (DEC32_SNAN))
+ abort ();
+ if (!__builtin_isnan (d32))
+ abort ();
+ (void) _Generic (DEC64_SNAN, _Decimal64 : 0);
+ if (!__builtin_isnan (DEC64_SNAN))
+ abort ();
+ if (!__builtin_isnan (d64))
+ abort ();
+ (void) _Generic (DEC128_SNAN, _Decimal128 : 0);
+ if (!__builtin_isnan (DEC128_SNAN))
+ abort ();
+ if (!__builtin_isnan (d128))
+ abort ();
+ exit (0);
+}
diff --git a/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-8.c b/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-8.c
new file mode 100644
index 00000000000..4169602fd9c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/dfp/c2x-float-dfp-8.c
@@ -0,0 +1,45 @@
+/* Test DEC*_SNAN macros. Test requiring runtime exceptions
+ support. */
+/* { dg-do run } */
+/* { dg-require-effective-target fenv_exceptions_dfp } */
+/* { dg-options "-std=c2x" } */
+
+#include <fenv.h>
+#include <float.h>
+
+volatile _Decimal32 d32 = DEC32_SNAN;
+volatile _Decimal64 d64 = DEC64_SNAN;
+volatile _Decimal128 d128 = DEC128_SNAN;
+
+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);
+}
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: float.h: C2x decimal signaling NaN macros
2020-11-05 23:21 float.h: C2x decimal signaling NaN macros Joseph Myers
@ 2020-11-06 17:53 ` Jeff Law
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2020-11-06 17:53 UTC (permalink / raw)
To: Joseph Myers, gcc-patches
On 11/5/20 4:21 PM, Joseph Myers wrote:
> C2x adds macros for decimal floating-point signaling NaNs to
> <float.h>. Add these macros to GCC's <float.h> implementation.
>
> Note that the current C2x draft has these under incorrect names
> D32_SNAN, D64_SNAN, D128_SNAN. The intent was to change the naming
> convention to be consistent with other <float.h> macros when they were
> moved to <float.h>, so DEC32_SNAN, DEC64_SNAN, DEC128_NAN, which this
> patch uses (as does the current draft integration of TS 18661-3 as an
> Annex to C2x, for its _Decimal* and _Decimal*x types).
>
> This patch is relative to a tree with
> <https://gcc.gnu.org/pipermail/gcc-patches/2020-October/557136.html>
> and
> <https://gcc.gnu.org/pipermail/gcc-patches/2020-November/558126.html>
> (both pending review) applied.
>
> Bootstrapped with no regressions for x86_64-pc-linux-gnu. OK to commit?
>
> gcc/
> 2020-11-05 Joseph Myers <joseph@codesourcery.com>
>
> * ginclude/float.h (DEC32_SNAN, DEC64_SNAN, DEC128_SNAN): New C2x
> macros.
>
> gcc/testsuite/
> 2020-11-05 Joseph Myers <joseph@codesourcery.com>
>
> * gcc.dg/dfp/c2x-float-dfp-7.c, gcc.dg/dfp/c2x-float-dfp-8.c: New
> tests.
> * gcc.dg/c2x-float-no-dfp-3.c: Also check that DEC32_SNAN,
> DEC64_SNAN and DEC128_SNAN are not defined.
OK
jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-11-06 17:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-05 23:21 float.h: C2x decimal signaling NaN macros Joseph Myers
2020-11-06 17:53 ` Jeff Law
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).