Re: [PATCH] libgfortran: Use __builtin_issignaling in libgfortran

2022-08-15 Thread Thomas Koenig via Gcc-patches



Hi Jakub,


The following patch makes use of the new __builtin_issignaling,
so it no longer needs the fallback implementation and can use
the builtin even where glibc provides the macro.

Bootstrapped/regtested on x86_64-linux, i686-linux, powerpc64le-linux
and powerpc64le-linux, ok for trunk?


OK. Can you mention PR 105105 in the ChangeLog when you commit?

Thanks for the patch!

Best regards

Thomas


[PATCH] libgfortran: Use __builtin_issignaling in libgfortran

2022-08-15 Thread Jakub Jelinek via Gcc-patches
Hi!

The following patch makes use of the new __builtin_issignaling,
so it no longer needs the fallback implementation and can use
the builtin even where glibc provides the macro.

Bootstrapped/regtested on x86_64-linux, i686-linux, powerpc64le-linux
and powerpc64le-linux, ok for trunk?

2022-08-15  Jakub Jelinek  

* ieee/ieee_helper.c: Don't include issignaling_fallback.h.
(CLASSMACRO): Use __builtin_issignaling instead of issignaling.
* ieee/issignaling_fallback.h: Removed.

--- libgfortran/ieee/ieee_helper.c.jj   2022-06-27 15:34:47.111928150 +0200
+++ libgfortran/ieee/ieee_helper.c  2022-08-12 13:21:00.922306862 +0200
@@ -26,13 +26,6 @@ see the files COPYING3 and COPYING.RUNTI
 #include "libgfortran.h"
 
 
-/* Check support for issignaling macro.  If not, we include our own
-   fallback implementation.  */
-#ifndef issignaling
-# include "issignaling_fallback.h"
-#endif
-
-
 /* Prototypes.  */
 
 extern int ieee_class_helper_4 (GFC_REAL_4 *);
@@ -94,7 +87,7 @@ enum {
  \
 if (res == IEEE_QUIET_NAN) \
 { \
-  if (issignaling (*value)) \
+  if (__builtin_issignaling (*value)) \
return IEEE_SIGNALING_NAN; \
   else \
return IEEE_QUIET_NAN; \
--- libgfortran/ieee/issignaling_fallback.h.jj  2022-06-28 13:14:45.332799201 
+0200
+++ libgfortran/ieee/issignaling_fallback.h 2022-08-12 13:20:17.784877531 
+0200
@@ -1,251 +0,0 @@
-/* Fallback implementation of issignaling macro.
-   Copyright (C) 2022 Free Software Foundation, Inc.
-   Contributed by Francois-Xavier Coudert 
-
-This file is part of the GNU Fortran runtime library (libgfortran).
-
-Libgfortran is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public
-License as published by the Free Software Foundation; either
-version 3 of the License, or (at your option) any later version.
-
-Libgfortran is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-Under Section 7 of GPL version 3, you are granted additional
-permissions described in the GCC Runtime Library Exception, version
-3.1, as published by the Free Software Foundation.
-
-You should have received a copy of the GNU General Public License and
-a copy of the GCC Runtime Library Exception along with this program;
-see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
-.  */
-
-#include "libgfortran.h"
-
-/* This header provides an implementation of the type-generic issignaling 
macro.
-   Some points of note:
-
- - This header is only included if the issignaling macro is not defined.
- - All targets for which Fortran IEEE modules are supported currently have
-   the high-order bit of the NaN mantissa clear for signaling (and set
-   for quiet), as recommended by IEEE.
- - We use the __*_IS_IEC_60559__ macros to make sure we only deal with 
formats
-   we know. For other floating-point formats, we consider all NaNs as 
quiet.
-
- */
-
-typedef union
-{
-  float value;
-  uint32_t word;
-} ieee_float_shape_type;
-
-static inline int
-__issignalingf (float x)
-{
-#if __FLT_IS_IEC_60559__
-  uint32_t xi;
-  ieee_float_shape_type u;
-
-  u.value = x;
-  xi = u.word;
-
-  xi ^= 0x0040;
-  return (xi & 0x7fff) > 0x7fc0;
-#else
-  return 0;
-#endif
-}
-
-
-typedef union
-{
-  double value;
-  uint64_t word;
-} ieee_double_shape_type;
-
-static inline int
-__issignaling (double x)
-{
-#if __DBL_IS_IEC_60559__
-  ieee_double_shape_type u;
-  uint64_t xi;
-
-  u.value = x;
-  xi = u.word;
-
-  xi ^= UINT64_C (0x0008);
-  return (xi & UINT64_C (0x7fff)) > UINT64_C (0x7ff8);
-#else
-  return 0;
-#endif
-}
-
-
-#if __LDBL_DIG__ == __DBL_DIG__
-
-/* Long double is the same as double.  */
-static inline int
-__issignalingl (long double x)
-{
-  return __issignaling (x);
-}
-
-#elif (__LDBL_DIG__ == 18) && __LDBL_IS_IEC_60559__
-
-/* Long double is x86 extended type.  */
-
-typedef union
-{
-  long double value;
-  struct
-  {
-#if __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__
-int sign_exponent:16;
-unsigned int empty:16;
-uint32_t msw;
-uint32_t lsw;
-#elif __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__
-uint32_t lsw;
-uint32_t msw;
-int sign_exponent:16;
-unsigned int empty:16;
-#endif
-  } parts;
-} ieee_long_double_shape_type;
-
-static inline int
-__issignalingl (long double x)
-{
-  int ret;
-  uint32_t exi, hxi, lxi;
-  ieee_long_double_shape_type u;
-
-  u.value = x;
-  exi = u.parts.sign_exponent;
-  hxi = u.parts.msw;
-  lxi = u.parts.lsw;
-
-  /* Pseudo numbers on x86 are always signaling.  */
-  ret = (exi & 0x7fff) && ((hxi & 0x8000) == 0);
-
-  hxi ^= 0x4000;
-  hxi |= (lxi | -lxi) >> 31;
-  return ret || (((exi & 0x7fff) == 0x7fff) && (hxi > 0xc000));
-}
-