* libgcc2.c (__negdi2, __addvsi3, __addvdi3, __subvsi3, __subvdi3,
authorghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 14 Nov 2003 02:23:13 +0000 (02:23 +0000)
committerghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 14 Nov 2003 02:23:13 +0000 (02:23 +0000)
__mulvsi3, __negvsi2, __negvdi2, __mulvdi3, __lshrdi3, __ashldi3,
__ashrdi3, __ffsDI2, __muldi3, __clzDI2, __ctzDI2, __parityDI2,
__udivmoddi4, __divdi3, __moddi3, __cmpdi2, __ucmpdi2,
__fixunstfDI, __fixunsxfDI, __fixunsdfDI, __fixunssfDI,
__floatdixf, __floatditf, __floatdidf, __floatdisf, __gcc_bcmp):
Const-ify and/or initialize automatic variables at declaration.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@73573 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/libgcc2.c

index 420ca4f..0faf0e8 100644 (file)
@@ -1,3 +1,13 @@
+2003-11-13  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
+
+       * libgcc2.c (__negdi2, __addvsi3, __addvdi3, __subvsi3, __subvdi3,
+       __mulvsi3, __negvsi2, __negvdi2, __mulvdi3, __lshrdi3, __ashldi3,
+       __ashrdi3, __ffsDI2, __muldi3, __clzDI2, __ctzDI2, __parityDI2,
+       __udivmoddi4, __divdi3, __moddi3, __cmpdi2, __ucmpdi2,
+       __fixunstfDI, __fixunsxfDI, __fixunsdfDI, __fixunssfDI,
+       __floatdixf, __floatditf, __floatdidf, __floatdisf, __gcc_bcmp):
+       Const-ify and/or initialize automatic variables at declaration.
+
 2003-11-13  Kazu Hirata  <kazu@cs.umass.edu>
 
        * config/h8300/lib1funcs.asm (divmodsi4): Replace all the uses
index 0827d83..34171ad 100644 (file)
@@ -63,13 +63,9 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 DWtype
 __negdi2 (DWtype u)
 {
-  DWunion w;
-  DWunion uu;
-
-  uu.ll = u;
-
-  w.s.low = -uu.s.low;
-  w.s.high = -uu.s.high - ((UWtype) w.s.low > 0);
+  const DWunion uu = {.ll = u};
+  const DWunion w = { {.low = -uu.s.low,
+                      .high = -uu.s.high - ((UWtype) -uu.s.low > 0) } };
 
   return w.ll;
 }
@@ -79,9 +75,7 @@ __negdi2 (DWtype u)
 Wtype
 __addvsi3 (Wtype a, Wtype b)
 {
-  Wtype w;
-
-  w = a + b;
+  const Wtype w = a + b;
 
   if (b >= 0 ? w < a : w > a)
     abort ();
@@ -94,9 +88,7 @@ __addvsi3 (Wtype a, Wtype b)
 DWtype
 __addvdi3 (DWtype a, DWtype b)
 {
-  DWtype w;
-
-  w = a + b;
+  const DWtype w = a + b;
 
   if (b >= 0 ? w < a : w > a)
     abort ();
@@ -109,9 +101,7 @@ __addvdi3 (DWtype a, DWtype b)
 Wtype
 __subvsi3 (Wtype a, Wtype b)
 {
-  DWtype w;
-
-  w = a - b;
+  const DWtype w = a - b;
 
   if (b >= 0 ? w > a : w < a)
     abort ();
@@ -124,9 +114,7 @@ __subvsi3 (Wtype a, Wtype b)
 DWtype
 __subvdi3 (DWtype a, DWtype b)
 {
-  DWtype w;
-
-  w = a - b;
+  const DWtype w = a - b;
 
   if (b >= 0 ? w > a : w < a)
     abort ();
@@ -140,9 +128,7 @@ __subvdi3 (DWtype a, DWtype b)
 Wtype
 __mulvsi3 (Wtype a, Wtype b)
 {
-  DWtype w;
-
-  w = (DWtype) a * (DWtype) b;
+  const DWtype w = (DWtype) a * (DWtype) b;
 
   if (((a >= 0) == (b >= 0))
       ? (UDWtype) w > (UDWtype) (((DWtype) 1 << (WORD_SIZE - 1)) - 1)
@@ -157,9 +143,7 @@ __mulvsi3 (Wtype a, Wtype b)
 Wtype
 __negvsi2 (Wtype a)
 {
-  Wtype w;
-
-  w  = -a;
+  const Wtype w = -a;
 
   if (a >= 0 ? w > 0 : w < 0)
     abort ();
@@ -172,9 +156,7 @@ __negvsi2 (Wtype a)
 DWtype
 __negvdi2 (DWtype a)
 {
-  DWtype w;
-
-  w  = -a;
+  const DWtype w = -a;
 
   if (a >= 0 ? w > 0 : w < 0)
     abort ();
@@ -230,10 +212,8 @@ __mulvdi3 (DWtype u, DWtype v)
 {
   /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
      but the checked multiplication needs only two.  */
-  DWunion uu, vv;
-
-  uu.ll = u;
-  vv.ll = v;
+  const DWunion uu = {.ll = u};
+  const DWunion vv = {.ll = v};
 
   if (__builtin_expect (uu.s.high == uu.s.low >> (WORD_SIZE - 1), 1))
     {
@@ -247,10 +227,11 @@ __mulvdi3 (DWtype u, DWtype v)
       else
        {
          /* Two multiplications.  */
-         DWunion w0, w1;
+         DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
+                       * (UDWtype) (UWtype) vv.s.low};
+         DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.low
+                       * (UDWtype) (UWtype) vv.s.high};
 
-         w0.ll = (UDWtype) (UWtype) uu.s.low * (UDWtype) (UWtype) vv.s.low;
-         w1.ll = (UDWtype) (UWtype) uu.s.low * (UDWtype) (UWtype) vv.s.high;
          if (vv.s.high < 0)
            w1.s.high -= uu.s.low;
          if (uu.s.low < 0)
@@ -269,10 +250,11 @@ __mulvdi3 (DWtype u, DWtype v)
        {
          /* v fits into a single Wtype.  */
          /* Two multiplications.  */
-         DWunion w0, w1;
+         DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
+                       * (UDWtype) (UWtype) vv.s.low};
+         DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.high
+                       * (UDWtype) (UWtype) vv.s.low};
 
-         w0.ll = (UDWtype) (UWtype) uu.s.low * (UDWtype) (UWtype) vv.s.low;
-         w1.ll = (UDWtype) (UWtype) uu.s.high * (UDWtype) (UWtype) vv.s.low;
          if (uu.s.high < 0)
            w1.s.high -= vv.s.low;
          if (vv.s.low < 0)
@@ -293,10 +275,8 @@ __mulvdi3 (DWtype u, DWtype v)
                {
                  if (uu.s.high == 0 && vv.s.high == 0)
                    {
-                     DWtype w;
-
-                     w = (UDWtype) (UWtype) uu.s.low
-                         * (UDWtype) (UWtype) vv.s.low;
+                     const DWtype w = (UDWtype) (UWtype) uu.s.low
+                       * (UDWtype) (UWtype) vv.s.low;
                      if (__builtin_expect (w >= 0, 1))
                        return w;
                    }
@@ -305,10 +285,9 @@ __mulvdi3 (DWtype u, DWtype v)
                {
                  if (uu.s.high == 0 && vv.s.high == (Wtype) -1)
                    {
-                     DWunion ww;
+                     DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
+                                   * (UDWtype) (UWtype) vv.s.low};
 
-                     ww.ll = (UDWtype) (UWtype) uu.s.low
-                             * (UDWtype) (UWtype) vv.s.low;
                      ww.s.high -= uu.s.low;
                      if (__builtin_expect (ww.s.high < 0, 1))
                        return ww.ll;
@@ -321,10 +300,9 @@ __mulvdi3 (DWtype u, DWtype v)
                {
                  if (uu.s.high == (Wtype) -1 && vv.s.high == 0)
                    {
-                     DWunion ww;
+                     DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
+                                   * (UDWtype) (UWtype) vv.s.low};
 
-                     ww.ll = (UDWtype) (UWtype) uu.s.low
-                             * (UDWtype) (UWtype) vv.s.low;
                      ww.s.high -= vv.s.low;
                      if (__builtin_expect (ww.s.high < 0, 1))
                        return ww.ll;
@@ -334,10 +312,9 @@ __mulvdi3 (DWtype u, DWtype v)
                {
                  if (uu.s.high == (Wtype) -1 && vv.s.high == (Wtype) - 1)
                    {
-                     DWunion ww;
+                     DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
+                                   * (UDWtype) (UWtype) vv.s.low};
 
-                     ww.ll = (UDWtype) (UWtype) uu.s.low
-                             * (UDWtype) (UWtype) vv.s.low;
                      ww.s.high -= uu.s.low;
                      ww.s.high -= vv.s.low;
                      if (__builtin_expect (ww.s.high >= 0, 1))
@@ -360,16 +337,13 @@ __mulvdi3 (DWtype u, DWtype v)
 DWtype
 __lshrdi3 (DWtype u, word_type b)
 {
-  DWunion w;
-  word_type bm;
-  DWunion uu;
-
   if (b == 0)
     return u;
 
-  uu.ll = u;
+  const DWunion uu = {.ll = u};
+  const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
+  DWunion w;
 
-  bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
   if (bm <= 0)
     {
       w.s.high = 0;
@@ -377,7 +351,7 @@ __lshrdi3 (DWtype u, word_type b)
     }
   else
     {
-      UWtype carries = (UWtype) uu.s.high << bm;
+      const UWtype carries = (UWtype) uu.s.high << bm;
 
       w.s.high = (UWtype) uu.s.high >> b;
       w.s.low = ((UWtype) uu.s.low >> b) | carries;
@@ -391,16 +365,13 @@ __lshrdi3 (DWtype u, word_type b)
 DWtype
 __ashldi3 (DWtype u, word_type b)
 {
-  DWunion w;
-  word_type bm;
-  DWunion uu;
-
   if (b == 0)
     return u;
 
-  uu.ll = u;
+  const DWunion uu = {.ll = u};
+  const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
+  DWunion w;
 
-  bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
   if (bm <= 0)
     {
       w.s.low = 0;
@@ -408,7 +379,7 @@ __ashldi3 (DWtype u, word_type b)
     }
   else
     {
-      UWtype carries = (UWtype) uu.s.low >> bm;
+      const UWtype carries = (UWtype) uu.s.low >> bm;
 
       w.s.low = (UWtype) uu.s.low << b;
       w.s.high = ((UWtype) uu.s.high << b) | carries;
@@ -422,16 +393,13 @@ __ashldi3 (DWtype u, word_type b)
 DWtype
 __ashrdi3 (DWtype u, word_type b)
 {
-  DWunion w;
-  word_type bm;
-  DWunion uu;
-
   if (b == 0)
     return u;
 
-  uu.ll = u;
+  const DWunion uu = {.ll = u};
+  const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
+  DWunion w;
 
-  bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
   if (bm <= 0)
     {
       /* w.s.high = 1..1 or 0..0 */
@@ -440,7 +408,7 @@ __ashrdi3 (DWtype u, word_type b)
     }
   else
     {
-      UWtype carries = (UWtype) uu.s.high << bm;
+      const UWtype carries = (UWtype) uu.s.high << bm;
 
       w.s.high = uu.s.high >> b;
       w.s.low = ((UWtype) uu.s.low >> b) | carries;
@@ -472,10 +440,9 @@ extern int __ffsDI2 (DWtype u);
 int
 __ffsDI2 (DWtype u)
 {
-  DWunion uu;
+  const DWunion uu = {.ll = u};
   UWtype word, count, add;
 
-  uu.ll = u;
   if (uu.s.low != 0)
     word = uu.s.low, add = 0;
   else if (uu.s.high != 0)
@@ -492,13 +459,10 @@ __ffsDI2 (DWtype u)
 DWtype
 __muldi3 (DWtype u, DWtype v)
 {
-  DWunion w;
-  DWunion uu, vv;
+  const DWunion uu = {.ll = u};
+  const DWunion vv = {.ll = v};
+  DWunion w = {.ll = __umulsidi3 (uu.s.low, vv.s.low)};
 
-  uu.ll = u,
-  vv.ll = v;
-
-  w.ll = __umulsidi3 (uu.s.low, vv.s.low);
   w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
               + (UWtype) uu.s.high * (UWtype) vv.s.low);
 
@@ -667,11 +631,10 @@ extern int __clzDI2 (UDWtype x);
 int
 __clzDI2 (UDWtype x)
 {
-  DWunion uu;
+  const DWunion uu = {.ll = x};
   UWtype word;
   Wtype ret, add;
 
-  uu.ll = x;
   if (uu.s.high)
     word = uu.s.high, add = 0;
   else
@@ -702,11 +665,10 @@ extern int __ctzDI2 (UDWtype x);
 int
 __ctzDI2 (UDWtype x)
 {
-  DWunion uu;
+  const DWunion uu = {.ll = x};
   UWtype word;
   Wtype ret, add;
 
-  uu.ll = x;
   if (uu.s.low)
     word = uu.s.low, add = 0;
   else
@@ -794,11 +756,8 @@ extern int __parityDI2 (UDWtype x);
 int
 __parityDI2 (UDWtype x)
 {
-  DWunion uu;
-  UWtype nx;
-
-  uu.ll = x;
-  nx = uu.s.low ^ uu.s.high;
+  const DWunion uu = {.ll = x};
+  UWtype nx = uu.s.low ^ uu.s.high;
 
 #if W_TYPE_SIZE > 64
 # error "fill out the table"
@@ -825,16 +784,13 @@ static inline __attribute__ ((__always_inline__))
 UDWtype
 __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
 {
-  DWunion ww;
-  DWunion nn, dd;
+  const DWunion nn = {.ll = n};
+  const DWunion dd = {.ll = d};
   DWunion rr;
   UWtype d0, d1, n0, n1, n2;
   UWtype q0, q1;
   UWtype b, bm;
 
-  nn.ll = n;
-  dd.ll = d;
-
   d0 = dd.s.low;
   d1 = dd.s.high;
   n0 = nn.s.low;
@@ -1034,8 +990,7 @@ __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
        }
     }
 
-  ww.s.low = q0;
-  ww.s.high = q1;
+  const DWunion ww = {{.low = q0, .high = q1}};
   return ww.ll;
 }
 #endif
@@ -1045,12 +1000,10 @@ DWtype
 __divdi3 (DWtype u, DWtype v)
 {
   word_type c = 0;
-  DWunion uu, vv;
+  DWunion uu = {.ll = u};
+  DWunion vv = {.ll = v};
   DWtype w;
 
-  uu.ll = u;
-  vv.ll = v;
-
   if (uu.s.high < 0)
     c = ~c,
     uu.ll = -uu.ll;
@@ -1071,12 +1024,10 @@ DWtype
 __moddi3 (DWtype u, DWtype v)
 {
   word_type c = 0;
-  DWunion uu, vv;
+  DWunion uu = {.ll = u};
+  DWunion vv = {.ll = v};
   DWtype w;
 
-  uu.ll = u;
-  vv.ll = v;
-
   if (uu.s.high < 0)
     c = ~c,
     uu.ll = -uu.ll;
@@ -1115,9 +1066,8 @@ __udivdi3 (UDWtype n, UDWtype d)
 word_type
 __cmpdi2 (DWtype a, DWtype b)
 {
-  DWunion au, bu;
-
-  au.ll = a, bu.ll = b;
+  const DWunion au = {.ll = a};
+  const DWunion bu = {.ll = b};
 
   if (au.s.high < bu.s.high)
     return 0;
@@ -1135,9 +1085,8 @@ __cmpdi2 (DWtype a, DWtype b)
 word_type
 __ucmpdi2 (DWtype a, DWtype b)
 {
-  DWunion au, bu;
-
-  au.ll = a, bu.ll = b;
+  const DWunion au = {.ll = a};
+  const DWunion bu = {.ll = b};
 
   if ((UWtype) au.s.high < (UWtype) bu.s.high)
     return 0;
@@ -1158,17 +1107,14 @@ __ucmpdi2 (DWtype a, DWtype b)
 DWtype
 __fixunstfDI (TFtype a)
 {
-  TFtype b;
-  UDWtype v;
-
   if (a < 0)
     return 0;
 
   /* Compute high word of result, as a flonum.  */
-  b = (a / HIGH_WORD_COEFF);
+  const TFtype b = (a / HIGH_WORD_COEFF);
   /* Convert that to fixed (but not to DWtype!),
      and shift it into the high word.  */
-  v = (UWtype) b;
+  UDWtype v = (UWtype) b;
   v <<= WORD_SIZE;
   /* Remove high part from the TFtype, leaving the low part as flonum.  */
   a -= (TFtype)v;
@@ -1200,17 +1146,14 @@ __fixtfdi (TFtype a)
 DWtype
 __fixunsxfDI (XFtype a)
 {
-  XFtype b;
-  UDWtype v;
-
   if (a < 0)
     return 0;
 
   /* Compute high word of result, as a flonum.  */
-  b = (a / HIGH_WORD_COEFF);
+  const XFtype b = (a / HIGH_WORD_COEFF);
   /* Convert that to fixed (but not to DWtype!),
      and shift it into the high word.  */
-  v = (UWtype) b;
+  UDWtype v = (UWtype) b;
   v <<= WORD_SIZE;
   /* Remove high part from the XFtype, leaving the low part as flonum.  */
   a -= (XFtype)v;
@@ -1242,17 +1185,15 @@ __fixxfdi (XFtype a)
 DWtype
 __fixunsdfDI (DFtype a)
 {
-  UWtype hi, lo;
-
   /* Get high part of result.  The division here will just moves the radix
      point and will not cause any rounding.  Then the conversion to integral
      type chops result as desired.  */
-  hi = a / HIGH_WORD_COEFF;
+  const UWtype hi = a / HIGH_WORD_COEFF;
 
   /* Get low part of result.  Convert `hi' to floating type and scale it back,
      then subtract this from the number being converted.  This leaves the low
      part.  Convert that to integral type.  */
-  lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
+  const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
 
   /* Assemble result from the two parts.  */
   return ((UDWtype) hi << WORD_SIZE) | lo;
@@ -1279,18 +1220,17 @@ __fixunssfDI (SFtype original_a)
   /* Convert the SFtype to a DFtype, because that is surely not going
      to lose any bits.  Some day someone else can write a faster version
      that avoids converting to DFtype, and verify it really works right.  */
-  DFtype a = original_a;
-  UWtype hi, lo;
+  const DFtype a = original_a;
 
   /* Get high part of result.  The division here will just moves the radix
      point and will not cause any rounding.  Then the conversion to integral
      type chops result as desired.  */
-  hi = a / HIGH_WORD_COEFF;
+  const UWtype hi = a / HIGH_WORD_COEFF;
 
   /* Get low part of result.  Convert `hi' to floating type and scale it back,
      then subtract this from the number being converted.  This leaves the low
      part.  Convert that to integral type.  */
-  lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
+  const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
 
   /* Assemble result from the two parts.  */
   return ((UDWtype) hi << WORD_SIZE) | lo;
@@ -1315,9 +1255,7 @@ __fixsfdi (SFtype a)
 XFtype
 __floatdixf (DWtype u)
 {
-  XFtype d;
-
-  d = (Wtype) (u >> WORD_SIZE);
+  XFtype d = (Wtype) (u >> WORD_SIZE);
   d *= HIGH_HALFWORD_COEFF;
   d *= HIGH_HALFWORD_COEFF;
   d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
@@ -1334,9 +1272,7 @@ __floatdixf (DWtype u)
 TFtype
 __floatditf (DWtype u)
 {
-  TFtype d;
-
-  d = (Wtype) (u >> WORD_SIZE);
+  TFtype d = (Wtype) (u >> WORD_SIZE);
   d *= HIGH_HALFWORD_COEFF;
   d *= HIGH_HALFWORD_COEFF;
   d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
@@ -1353,9 +1289,7 @@ __floatditf (DWtype u)
 DFtype
 __floatdidf (DWtype u)
 {
-  DFtype d;
-
-  d = (Wtype) (u >> WORD_SIZE);
+  DFtype d = (Wtype) (u >> WORD_SIZE);
   d *= HIGH_HALFWORD_COEFF;
   d *= HIGH_HALFWORD_COEFF;
   d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
@@ -1376,11 +1310,6 @@ __floatdidf (DWtype u)
 SFtype
 __floatdisf (DWtype u)
 {
-  /* Do the calculation in DFmode
-     so that we don't lose any of the precision of the high word
-     while multiplying it.  */
-  DFtype f;
-
   /* Protect against double-rounding error.
      Represent any low-order bits, that might be truncated in DFmode,
      by a bit that won't be lost.  The bit can go in anywhere below the
@@ -1401,7 +1330,10 @@ __floatdisf (DWtype u)
            }
        }
     }
-  f = (Wtype) (u >> WORD_SIZE);
+  /* Do the calculation in DFmode
+     so that we don't lose any of the precision of the high word
+     while multiplying it.  */
+  DFtype f = (Wtype) (u >> WORD_SIZE);
   f *= HIGH_HALFWORD_COEFF;
   f *= HIGH_HALFWORD_COEFF;
   f += (UWtype) (u & (HIGH_WORD_COEFF - 1));
@@ -1510,7 +1442,7 @@ __gcc_bcmp (const unsigned char *s1, const unsigned char *s2, size_t size)
 {
   while (size > 0)
     {
-      unsigned char c1 = *s1++, c2 = *s2++;
+      const unsigned char c1 = *s1++, c2 = *s2++;
       if (c1 != c2)
        return c1 - c2;
       size--;