OSDN Git Service

Fix PR32824.
[pf3gnuchains/gcc-fork.git] / gcc / sreal.c
index f69cbb1..415a02c 100644 (file)
@@ -1,11 +1,11 @@
 /* Simple data type for positive real numbers for the GNU compiler.
 /* Simple data type for positive real numbers for the GNU compiler.
-   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
 GCC 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
 
 This file is part of GCC.
 
 GCC 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 2, or (at your option) any later
+Software Foundation; either version 3, or (at your option) any later
 version.
 
 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
 version.
 
 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
@@ -14,9 +14,8 @@ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.
 
 You should have received a copy of the GNU General Public License
 for more details.
 
 You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING.  If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.  */
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
 
 /* This library supports positive real numbers and 0;
    inf and nan are NOT supported.
 
 /* This library supports positive real numbers and 0;
    inf and nan are NOT supported.
@@ -24,7 +23,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
    Value of sreal is
        x = sig * 2 ^ exp
 
    Value of sreal is
        x = sig * 2 ^ exp
-   where 
+   where
        sig = significant
          (for < 64-bit machines sig = sig_lo + sig_hi * 2 ^ SREAL_PART_BITS)
        exp = exponent
        sig = significant
          (for < 64-bit machines sig = sig_lo + sig_hi * 2 ^ SREAL_PART_BITS)
        exp = exponent
@@ -34,14 +33,14 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
    otherwise two HOST_WIDE_INTs are used for the significant.
    Only a half of significant bits is used (in normalized sreals) so that we do
    not have problems with overflow, for example when c->sig = a->sig * b->sig.
    otherwise two HOST_WIDE_INTs are used for the significant.
    Only a half of significant bits is used (in normalized sreals) so that we do
    not have problems with overflow, for example when c->sig = a->sig * b->sig.
-   So the precission for 64-bit and 32-bit machines is 32-bit.
-                       
+   So the precision for 64-bit and 32-bit machines is 32-bit.
+
    Invariant: The numbers are normalized before and after each call of sreal_*.
 
    Normalized sreals:
    All numbers (except zero) meet following conditions:
         SREAL_MIN_SIG <= sig && sig <= SREAL_MAX_SIG
    Invariant: The numbers are normalized before and after each call of sreal_*.
 
    Normalized sreals:
    All numbers (except zero) meet following conditions:
         SREAL_MIN_SIG <= sig && sig <= SREAL_MAX_SIG
-       -SREAL_MAX_EXP <= exp && exp <= SREAL_MAX_EXP 
+       -SREAL_MAX_EXP <= exp && exp <= SREAL_MAX_EXP
 
    If the number would be too large, it is set to upper bounds of these
    conditions.
 
    If the number would be too large, it is set to upper bounds of these
    conditions.
@@ -56,16 +55,14 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "tm.h"
 #include "sreal.h"
 
 #include "tm.h"
 #include "sreal.h"
 
-static inline void copy                PARAMS ((sreal *, sreal *));
-static inline void shift_right PARAMS ((sreal *, int));
-static void normalize          PARAMS ((sreal *));
+static inline void copy (sreal *, sreal *);
+static inline void shift_right (sreal *, int);
+static void normalize (sreal *);
 
 /* Print the content of struct sreal.  */
 
 void
 
 /* Print the content of struct sreal.  */
 
 void
-dump_sreal (file, x)
-     FILE *file;
-     sreal *x;
+dump_sreal (FILE *file, sreal *x)
 {
 #if SREAL_PART_BITS < 32
   fprintf (file, "((" HOST_WIDE_INT_PRINT_UNSIGNED " * 2^16 + "
 {
 #if SREAL_PART_BITS < 32
   fprintf (file, "((" HOST_WIDE_INT_PRINT_UNSIGNED " * 2^16 + "
@@ -79,9 +76,7 @@ dump_sreal (file, x)
 /* Copy the sreal number.  */
 
 static inline void
 /* Copy the sreal number.  */
 
 static inline void
-copy (r, a)
-     sreal *r;
-     sreal *a;
+copy (sreal *r, sreal *a)
 {
 #if SREAL_PART_BITS < 32
   r->sig_lo = a->sig_lo;
 {
 #if SREAL_PART_BITS < 32
   r->sig_lo = a->sig_lo;
@@ -96,21 +91,14 @@ copy (r, a)
    When the most significant bit shifted out is 1, add 1 to X (rounding).  */
 
 static inline void
    When the most significant bit shifted out is 1, add 1 to X (rounding).  */
 
 static inline void
-shift_right (x, s)
-     sreal *x;
-     int s;
+shift_right (sreal *x, int s)
 {
 {
-#ifdef ENABLE_CHECKING
-  if (s <= 0 || s > SREAL_BITS)
-    abort ();
-  if (x->exp + s > SREAL_MAX_EXP)
-    {
-      /* Exponent should never be so large because shift_right is used only by
-        sreal_add and sreal_sub ant thus the number cannot be shifted out from
-        exponent range.  */
-      abort ();
-    }
-#endif
+  gcc_assert (s > 0);
+  gcc_assert (s <= SREAL_BITS);
+  /* Exponent should never be so large because shift_right is used only by
+     sreal_add and sreal_sub ant thus the number cannot be shifted out from
+     exponent range.  */
+  gcc_assert (x->exp + s <= SREAL_MAX_EXP);
 
   x->exp += s;
 
 
   x->exp += s;
 
@@ -143,13 +131,12 @@ shift_right (x, s)
 /* Normalize *X.  */
 
 static void
 /* Normalize *X.  */
 
 static void
-normalize (x)
-     sreal *x;
+normalize (sreal *x)
 {
 #if SREAL_PART_BITS < 32
   int shift;
   HOST_WIDE_INT mask;
 {
 #if SREAL_PART_BITS < 32
   int shift;
   HOST_WIDE_INT mask;
-  
+
   if (x->sig_lo == 0 && x->sig_hi == 0)
     {
       x->exp = -SREAL_MAX_EXP;
   if (x->sig_lo == 0 && x->sig_hi == 0)
     {
       x->exp = -SREAL_MAX_EXP;
@@ -280,10 +267,7 @@ normalize (x)
 /* Set *R to SIG * 2 ^ EXP.  Return R.  */
 
 sreal *
 /* Set *R to SIG * 2 ^ EXP.  Return R.  */
 
 sreal *
-sreal_init (r, sig, exp)
-     sreal *r;
-     unsigned HOST_WIDE_INT sig;
-     signed int exp;
+sreal_init (sreal *r, unsigned HOST_WIDE_INT sig, signed int exp)
 {
 #if SREAL_PART_BITS < 32
   r->sig_lo = 0;
 {
 #if SREAL_PART_BITS < 32
   r->sig_lo = 0;
@@ -300,8 +284,7 @@ sreal_init (r, sig, exp)
 /* Return integer value of *R.  */
 
 HOST_WIDE_INT
 /* Return integer value of *R.  */
 
 HOST_WIDE_INT
-sreal_to_int (r)
-     sreal *r;
+sreal_to_int (sreal *r)
 {
 #if SREAL_PART_BITS < 32
   if (r->exp <= -SREAL_BITS)
 {
 #if SREAL_PART_BITS < 32
   if (r->exp <= -SREAL_BITS)
@@ -325,9 +308,7 @@ sreal_to_int (r)
 /* Compare *A and *B. Return -1 if *A < *B, 1 if *A > *B and 0 if *A == *B.  */
 
 int
 /* Compare *A and *B. Return -1 if *A < *B, 1 if *A > *B and 0 if *A == *B.  */
 
 int
-sreal_compare (a, b)
-     sreal *a;
-     sreal *b;
+sreal_compare (sreal *a, sreal *b)
 {
   if (a->exp > b->exp)
     return 1;
 {
   if (a->exp > b->exp)
     return 1;
@@ -354,10 +335,7 @@ sreal_compare (a, b)
 /* *R = *A + *B.  Return R.  */
 
 sreal *
 /* *R = *A + *B.  Return R.  */
 
 sreal *
-sreal_add (r, a, b)
-  sreal *r;
-  sreal *a;
-  sreal *b;
+sreal_add (sreal *r, sreal *a, sreal *b)
 {
   int dexp;
   sreal tmp;
 {
   int dexp;
   sreal tmp;
@@ -411,19 +389,13 @@ sreal_add (r, a, b)
 /* *R = *A - *B.  Return R.  */
 
 sreal *
 /* *R = *A - *B.  Return R.  */
 
 sreal *
-sreal_sub (r, a, b)
-  sreal *r;
-  sreal *a;
-  sreal *b;
+sreal_sub (sreal *r, sreal *a, sreal *b)
 {
   int dexp;
   sreal tmp;
   sreal *bb;
 
 {
   int dexp;
   sreal tmp;
   sreal *bb;
 
-  if (sreal_compare (a, b) < 0)
-    {
-      abort ();
-    }
+  gcc_assert (sreal_compare (a, b) >= 0);
 
   dexp = a->exp - b->exp;
   r->exp = a->exp;
 
   dexp = a->exp - b->exp;
   r->exp = a->exp;
@@ -467,10 +439,7 @@ sreal_sub (r, a, b)
 /* *R = *A * *B.  Return R.  */
 
 sreal *
 /* *R = *A * *B.  Return R.  */
 
 sreal *
-sreal_mul (r, a, b)
-     sreal *r;
-     sreal *a;
-     sreal *b;
+sreal_mul (sreal *r, sreal *a, sreal *b)
 {
 #if SREAL_PART_BITS < 32
   if (a->sig_hi < SREAL_MIN_SIG || b->sig_hi < SREAL_MIN_SIG)
 {
 #if SREAL_PART_BITS < 32
   if (a->sig_hi < SREAL_MIN_SIG || b->sig_hi < SREAL_MIN_SIG)
@@ -526,19 +495,13 @@ sreal_mul (r, a, b)
 /* *R = *A / *B.  Return R.  */
 
 sreal *
 /* *R = *A / *B.  Return R.  */
 
 sreal *
-sreal_div (r, a, b)
-     sreal *r;
-     sreal *a;
-     sreal *b;
+sreal_div (sreal *r, sreal *a, sreal *b)
 {
 #if SREAL_PART_BITS < 32
   unsigned HOST_WIDE_INT tmp, tmp1, tmp2;
 
 {
 #if SREAL_PART_BITS < 32
   unsigned HOST_WIDE_INT tmp, tmp1, tmp2;
 
-  if (b->sig_hi < SREAL_MIN_SIG)
-    {
-      abort ();
-    }
-  else if (a->sig_hi < SREAL_MIN_SIG)
+  gcc_assert (b->sig_hi >= SREAL_MIN_SIG);
+  if (a->sig_hi < SREAL_MIN_SIG)
     {
       r->sig_hi = 0;
       r->sig_lo = 0;
     {
       r->sig_hi = 0;
       r->sig_lo = 0;
@@ -571,16 +534,10 @@ sreal_div (r, a, b)
       normalize (r);
     }
 #else
       normalize (r);
     }
 #else
-  if (b->sig == 0)
-    {
-      abort ();
-    }
-  else
-    {
-      r->sig = (a->sig << SREAL_PART_BITS) / b->sig;
-      r->exp = a->exp - b->exp - SREAL_PART_BITS;
-      normalize (r);
-    }
+  gcc_assert (b->sig != 0);
+  r->sig = (a->sig << SREAL_PART_BITS) / b->sig;
+  r->exp = a->exp - b->exp - SREAL_PART_BITS;
+  normalize (r);
 #endif
   return r;
 }
 #endif
   return r;
 }