move bigadd out into separate function, use it
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 24 Apr 2022 17:35:18 +0000 (18:35 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 24 Apr 2022 17:35:18 +0000 (18:35 +0100)
openpower/sv/biginteger/divgnu64.c

index 593b126d349f7e4b9c08bcc4a9d59e7579e835d0..ebb46d1cc1416edba20d2d7d835f5a1e098f2943 100644 (file)
@@ -75,6 +75,20 @@ bool bigmul(unsigned long long qhat, unsigned product[], unsigned vn[],
     return carry != 0;
 }
 
+bool bigadd(unsigned result[], unsigned vn[], unsigned un[],
+           int m, int n, bool ca)
+{
+    // VL = n + 1
+    // sv.subfe un_j.v, product.v, un_j.v
+    for (int i = 0; i <= n; i++)
+    {
+        uint64_t value = (uint64_t)vn[i] + (uint64_t)un[i] + ca;
+        ca = value >> 32 != 0;
+        result[i] = value;
+    }
+    return ca;
+}
+
 bool bigsub(unsigned result[], unsigned vn[], unsigned un[],
            int m, int n, bool ca)
 {
@@ -189,14 +203,7 @@ int divmnu(unsigned q[], unsigned r[], const unsigned u[], const unsigned v[],
         if (need_fixup)
         {                    // If we subtracted too
             q[j] = q[j] - 1; // much, add back.
-            k = 0;
-            for (i = 0; i < n; i++)
-            {
-                t = (unsigned long long)un[i + j] + vn[i] + k;
-                un[i + j] = t;
-                k = t >> 32;
-            }
-            un[j + n] = un[j + n] + k;
+            bigadd(un_j, vn, un_j, m, n, 0);
         }
     } // End j.
     // If the caller wants the remainder, unnormalize