Re: builtins: Add DFP signaling NaN built-in functions

2020-11-06 Thread Jeff Law via Gcc-patches


On 11/4/20 5:35 PM, Joseph Myers wrote:
> Add built-in functions __builtin_nansd32, __builtin_nansd64 and
> __builtin_nansd128 to return signaling NaNs of decimal floating-point
> types, analogous to the functions already present for binary
> floating-point types.
>
> This patch, independent of
> 
> (pending review), is in preparation for adding the  macros
> for such signaling NaNs that are in C2x, analogous to the macros for
> other types that are in that patch.
>
> Bootstrapped with no regressions for x86_64-pc-linux-gnu.  Also ran
> the new tests for powerpc64le-linux-gnu to confirm they do work in the
> case (hardware DFP) where floating-point exceptions are supported for
> DFP.  OK to commit?
>
> gcc/
> 2020-11-05  Joseph Myers  
>
>   * builtins.def (BUILT_IN_NANSD32, BUILT_IN_NANSD64)
>   (BUILT_IN_NANSD128): New built-in functions.
>   * fold-const-call.c (fold_const_call): Handle the new built-in
>   functions.
>   * doc/extend.texi (__builtin_nansd32, __builtin_nansd64)
>   (__builtin_nansd128): Document.
>   * doc/sourcebuild.texi (Effective-Target Keywords): Document
>   fenv_exceptions_dfp.
>
> gcc/testsuite/
> 2020-11-05  Joseph Myers  
>
>   * lib/target-supports.exp
>   (check_effective_target_fenv_exceptions_dfp): New.
>   * gcc.dg/dfp/builtin-snan-1.c, gcc.dg/dfp/builtin-snan-2.c: New
>   tests.

OK

jeff




builtins: Add DFP signaling NaN built-in functions

2020-11-04 Thread Joseph Myers
Add built-in functions __builtin_nansd32, __builtin_nansd64 and
__builtin_nansd128 to return signaling NaNs of decimal floating-point
types, analogous to the functions already present for binary
floating-point types.

This patch, independent of

(pending review), is in preparation for adding the  macros
for such signaling NaNs that are in C2x, analogous to the macros for
other types that are in that patch.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.  Also ran
the new tests for powerpc64le-linux-gnu to confirm they do work in the
case (hardware DFP) where floating-point exceptions are supported for
DFP.  OK to commit?

gcc/
2020-11-05  Joseph Myers  

* builtins.def (BUILT_IN_NANSD32, BUILT_IN_NANSD64)
(BUILT_IN_NANSD128): New built-in functions.
* fold-const-call.c (fold_const_call): Handle the new built-in
functions.
* doc/extend.texi (__builtin_nansd32, __builtin_nansd64)
(__builtin_nansd128): Document.
* doc/sourcebuild.texi (Effective-Target Keywords): Document
fenv_exceptions_dfp.

gcc/testsuite/
2020-11-05  Joseph Myers  

* lib/target-supports.exp
(check_effective_target_fenv_exceptions_dfp): New.
* gcc.dg/dfp/builtin-snan-1.c, gcc.dg/dfp/builtin-snan-2.c: New
tests.

diff --git a/gcc/builtins.def b/gcc/builtins.def
index 68f2da6cda4..b4494c712a1 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 7a6ecce6a84..e6a9bdf1099 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 49316a5d0ff..b3c5e530423 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 11ed47db3d9..3548fab78cd 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 000..49a32c87546
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/dfp/builtin-snan-1.c
@@ -0,0 +1,23 @@
+/* Test __builtin_nansd* functions.  Te