[llvm] Revert "[APInt] Remove multiplicativeInverse with explicit modulus (#… (PR #87812)

via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 5 11:00:16 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff e915b7d8166a870834868bcf7de85cb5e96a08ec 02329106f64c176507512202bb25ffb3cc6767f4 -- llvm/include/llvm/ADT/APInt.h llvm/lib/Support/APInt.cpp llvm/unittests/ADT/APIntTest.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index f8f699f8f6..e716a27145 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -1247,7 +1247,7 @@ APInt APInt::sqrt() const {
 /// (potentially large) APInts around.
 /// WARNING: a value of '0' may be returned,
 ///          signifying that no multiplicative inverse exists!
-APInt APInt::multiplicativeInverse(const APInt& modulo) const {
+APInt APInt::multiplicativeInverse(const APInt &modulo) const {
   assert(ult(modulo) && "This APInt must be smaller than the modulo");
 
   // Using the properties listed at the following web page (accessed 06/21/08):
@@ -1258,18 +1258,18 @@ APInt APInt::multiplicativeInverse(const APInt& modulo) const {
   // inverse exists, but may not suffice for the general extended Euclidean
   // algorithm.
 
-  APInt r[2] = { modulo, *this };
-  APInt t[2] = { APInt(BitWidth, 0), APInt(BitWidth, 1) };
+  APInt r[2] = {modulo, *this};
+  APInt t[2] = {APInt(BitWidth, 0), APInt(BitWidth, 1)};
   APInt q(BitWidth, 0);
 
   unsigned i;
-  for (i = 0; r[i^1] != 0; i ^= 1) {
+  for (i = 0; r[i ^ 1] != 0; i ^= 1) {
     // An overview of the math without the confusing bit-flipping:
     // q = r[i-2] / r[i-1]
     // r[i] = r[i-2] % r[i-1]
     // t[i] = t[i-2] - t[i-1] * q
-    udivrem(r[i], r[i^1], q, r[i]);
-    t[i] -= t[i^1] * q;
+    udivrem(r[i], r[i ^ 1], q, r[i]);
+    t[i] -= t[i ^ 1] * q;
   }
 
   // If this APInt and the modulo are not coprime, there is no multiplicative

``````````

</details>


https://github.com/llvm/llvm-project/pull/87812


More information about the llvm-commits mailing list