wide-int.cc (canonize_uhwi): New function.
authorJakub Jelinek <jakub@redhat.com>
Tue, 2 Feb 2016 19:44:16 +0000 (20:44 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 2 Feb 2016 19:44:16 +0000 (20:44 +0100)
* wide-int.cc (canonize_uhwi): New function.
(wi::divmod_internal): Use it.

From-SVN: r233092

gcc/ChangeLog
gcc/wide-int.cc

index 2cb845618556a68c05abade583988dd9a3fc9973..8c59956e30b39ef19238d305c4337f34ddbdfb39 100644 (file)
@@ -1,3 +1,8 @@
+2016-02-02  Jakub Jelinek  <jakub@redhat.com>
+
+       * wide-int.cc (canonize_uhwi): New function.
+       (wi::divmod_internal): Use it.
+
 2016-02-02  James Norris  <jnorris@codesourcery.com
 
        * gimplify.c (omp_notice_variable): Add usage check.
index 5fcec2ee790ddfc29a401d42c5f2c0f815709d7b..8648e7dc286342bc06885af11279871ef79622a9 100644 (file)
@@ -118,6 +118,20 @@ canonize (HOST_WIDE_INT *val, unsigned int len, unsigned int precision)
   return 1;
 }
 
+/* VAL[0] is the unsigned result of an operation.  Canonize it by adding
+   another 0 block if needed, and return number of blocks needed.  */
+
+static inline unsigned int
+canonize_uhwi (HOST_WIDE_INT *val, unsigned int precision)
+{
+  if (val[0] < 0 && precision > HOST_BITS_PER_WIDE_INT)
+    {
+      val[1] = 0;
+      return 2;
+    }
+  return 1;
+}
+
 /*
  * Conversion routines in and out of wide_int.
  */
@@ -1793,25 +1807,12 @@ wi::divmod_internal (HOST_WIDE_INT *quotient, unsigned int *remainder_len,
       if (quotient)
        {
          quotient[0] = o0 / o1;
-         if (o1 == 1
-             && (HOST_WIDE_INT) o0 < 0
-             && dividend_prec > HOST_BITS_PER_WIDE_INT)
-           {
-             quotient[1] = 0;
-             quotient_len = 2;
-           }
+         quotient_len = canonize_uhwi (quotient, dividend_prec);
        }
       if (remainder)
        {
          remainder[0] = o0 % o1;
-         if ((HOST_WIDE_INT) remainder[0] < 0
-             && dividend_prec > HOST_BITS_PER_WIDE_INT)
-           {
-             remainder[1] = 0;
-             *remainder_len = 2;
-           }
-         else
-           *remainder_len = 1;
+         *remainder_len = canonize_uhwi (remainder, dividend_prec);
        }
       return quotient_len;
     }