diff libgcc/config/s390/32/_fixtfdi.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents 77e2b8dfacca
children 84e7813d76e9
line wrap: on
line diff
--- a/libgcc/config/s390/32/_fixtfdi.c	Sun Aug 21 07:07:55 2011 +0900
+++ b/libgcc/config/s390/32/_fixtfdi.c	Fri Oct 27 22:46:09 2017 +0900
@@ -1,6 +1,5 @@
 /* Definitions of target machine for GNU compiler, for IBM S/390
-   Copyright (C) 1999, 2000, 2001, 2007, 2008 and 2009
-   Free Software Foundation, Inc.
+   Copyright (C) 1999-2017 Free Software Foundation, Inc.
    Contributed by Hartmut Penner (hpenner@de.ibm.com) and
                   Ulrich Weigand (uweigand@de.ibm.com).
 
@@ -25,18 +24,22 @@
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
+#ifndef __s390x__
+
 #define EXPD(fp)	   (((fp.l.i[0]) >> 16) & 0x7FFF)
 #define EXPONENT_BIAS	   16383
 #define MANTISSA_BITS      112
 #define PRECISION          (MANTISSA_BITS + 1)
 #define SIGNBIT		   0x80000000
-#define SIGND(fp)	   ((fp.l.i[0]) & SIGNBIT)
+#define SIGN(fp)	   ((fp.l.i[0]) & SIGNBIT)
 #define MANTD_HIGH_LL(fp)  ((fp.ll[0] & HIGH_LL_FRAC_MASK) | HIGH_LL_UNIT_BIT)
 #define MANTD_LOW_LL(fp)   (fp.ll[1])
 #define FRACD_ZERO_P(fp)   (!fp.ll[1] && !(fp.ll[0] & HIGH_LL_FRAC_MASK))
 #define HIGH_LL_FRAC_BITS  48
 #define HIGH_LL_UNIT_BIT   ((UDItype_x)1 << HIGH_LL_FRAC_BITS)
 #define HIGH_LL_FRAC_MASK  (HIGH_LL_UNIT_BIT - 1)
+#define LLONG_MAX       9223372036854775807LL
+#define LLONG_MIN       (-LLONG_MAX - 1LL)
 
 typedef int DItype_x __attribute__ ((mode (DI)));
 typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
@@ -51,6 +54,12 @@
   UDItype_x ll[2];   /* 64 bit parts: 0 upper, 1 lower */
 };
 
+static __inline__ void
+fexceptdiv (float d, float e)
+{
+  __asm__ __volatile__ ("debr %0,%1" : : "f" (d), "f" (e) );
+}
+
 DItype_x __fixtfdi (long double a1);
 
 /* convert double to unsigned int */
@@ -78,7 +87,11 @@
 
     /* NaN: All exponent bits set and a nonzero fraction.  */
     if ((EXPD(dl1) == 0x7fff) && !FRACD_ZERO_P (dl1))
-      return 0x8000000000000000ULL;
+      {
+	/* C99 Annex F.4 requires an "invalid" exception to be thrown.  */
+	fexceptdiv (0.0, 0.0);
+	return 0x8000000000000000ULL;
+      }
 
     /* One extra bit is needed for the unit bit which is appended by
        MANTD_HIGH_LL on the left of the matissa.  */
@@ -91,12 +104,19 @@
        or more.  */
     if (exp >= 0)
       {
-	l = 1ULL << 63; /* long long min */
-	return SIGND (dl1) ? l : l - 1;
+	/* Don't throw an exception for -1p+63  */
+	if (!SIGN (dl1)
+	    || exp > 0
+	    || MANTD_LOW_LL (dl1) >> (HIGH_LL_FRAC_BITS + 1)
+	    || (dl1.ll[0] & HIGH_LL_FRAC_MASK))
+	  /* C99 Annex F.4 requires an "invalid" exception to be thrown.  */
+	  fexceptdiv (0.0, 0.0);
+	return SIGN (dl1) ? LLONG_MIN : LLONG_MAX;
       }
 
     l = MANTD_LOW_LL (dl1) >> (HIGH_LL_FRAC_BITS + 1)
         | MANTD_HIGH_LL (dl1) << (64 - (HIGH_LL_FRAC_BITS + 1));
 
-    return SIGND (dl1) ? -(l >> -exp) : l >> -exp;
+    return SIGN (dl1) ? -(l >> -exp) : l >> -exp;
 }
+#endif /* !__s390x__ */