]> granicus.if.org Git - llvm/commitdiff
[APInt] Use getNumWords function in udiv/urem/udivrem instead of reimplementinging it.
authorCraig Topper <craig.topper@gmail.com>
Wed, 10 May 2017 07:50:15 +0000 (07:50 +0000)
committerCraig Topper <craig.topper@gmail.com>
Wed, 10 May 2017 07:50:15 +0000 (07:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302625 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/APInt.cpp

index 3bfd6ba5ec70b177513d0eaca7186f8adf3cdf3b..99a7b18b1731293982c9a59de01ac2e58b5e67ee 100644 (file)
@@ -1578,11 +1578,9 @@ APInt APInt::udiv(const APInt& RHS) const {
   }
 
   // Get some facts about the LHS and RHS number of bits and words
-  unsigned rhsBits = RHS.getActiveBits();
-  unsigned rhsWords = !rhsBits ? 0 : (APInt::whichWord(rhsBits - 1) + 1);
+  unsigned rhsWords = getNumWords(RHS.getActiveBits());
   assert(rhsWords && "Divided by zero???");
-  unsigned lhsBits = this->getActiveBits();
-  unsigned lhsWords = !lhsBits ? 0 : (APInt::whichWord(lhsBits - 1) + 1);
+  unsigned lhsWords = getNumWords(getActiveBits());
 
   // Deal with some degenerate cases
   if (!lhsWords)
@@ -1623,12 +1621,10 @@ APInt APInt::urem(const APInt& RHS) const {
   }
 
   // Get some facts about the LHS
-  unsigned lhsBits = getActiveBits();
-  unsigned lhsWords = !lhsBits ? 0 : (whichWord(lhsBits - 1) + 1);
+  unsigned lhsWords = getNumWords(getActiveBits());
 
   // Get some facts about the RHS
-  unsigned rhsBits = RHS.getActiveBits();
-  unsigned rhsWords = !rhsBits ? 0 : (APInt::whichWord(rhsBits - 1) + 1);
+  unsigned rhsWords = getNumWords(RHS.getActiveBits());
   assert(rhsWords && "Performing remainder operation by zero ???");
 
   // Check the degenerate cases
@@ -1677,10 +1673,8 @@ void APInt::udivrem(const APInt &LHS, const APInt &RHS,
   }
 
   // Get some size facts about the dividend and divisor
-  unsigned lhsBits  = LHS.getActiveBits();
-  unsigned lhsWords = !lhsBits ? 0 : (APInt::whichWord(lhsBits - 1) + 1);
-  unsigned rhsBits  = RHS.getActiveBits();
-  unsigned rhsWords = !rhsBits ? 0 : (APInt::whichWord(rhsBits - 1) + 1);
+  unsigned lhsWords = getNumWords(LHS.getActiveBits());
+  unsigned rhsWords = getNumWords(RHS.getActiveBits());
 
   // Check the degenerate cases
   if (lhsWords == 0) {