Index: lib/Support/APInt.cpp =================================================================== --- lib/Support/APInt.cpp +++ lib/Support/APInt.cpp @@ -1254,20 +1254,20 @@ // The DEBUG macros here tend to be spam in the debug output if you're not // debugging this code. Disable them unless KNUTH_DEBUG is defined. -#pragma push_macro("LLVM_DEBUG") -#ifndef KNUTH_DEBUG -#undef LLVM_DEBUG -#define LLVM_DEBUG(X) \ +#ifdef KNUTH_DEBUG +#define KNUTH_LLVM_DEBUG(X) LLVM_DEBUG(X) +#else +#define KNUTH_LLVM_DEBUG(X) \ do { \ } while (false) #endif - LLVM_DEBUG(dbgs() << "KnuthDiv: m=" << m << " n=" << n << '\n'); - LLVM_DEBUG(dbgs() << "KnuthDiv: original:"); - LLVM_DEBUG(for (int i = m + n; i >= 0; i--) dbgs() << " " << u[i]); - LLVM_DEBUG(dbgs() << " by"); - LLVM_DEBUG(for (int i = n; i > 0; i--) dbgs() << " " << v[i - 1]); - LLVM_DEBUG(dbgs() << '\n'); + KNUTH_LLVM_DEBUG(dbgs() << "KnuthDiv: m=" << m << " n=" << n << '\n'); + KNUTH_LLVM_DEBUG(dbgs() << "KnuthDiv: original:"); + KNUTH_LLVM_DEBUG(for (int i = m + n; i >= 0; i--) dbgs() << " " << u[i]); + KNUTH_LLVM_DEBUG(dbgs() << " by"); + KNUTH_LLVM_DEBUG(for (int i = n; i > 0; i--) dbgs() << " " << v[i - 1]); + KNUTH_LLVM_DEBUG(dbgs() << '\n'); // D1. [Normalize.] Set d = b / (v[n-1] + 1) and multiply all the digits of // u and v by d. Note that we have taken Knuth's advice here to use a power // of 2 value for d such that d * v[n-1] >= b/2 (b is the base). A power of @@ -1293,16 +1293,16 @@ } u[m+n] = u_carry; - LLVM_DEBUG(dbgs() << "KnuthDiv: normal:"); - LLVM_DEBUG(for (int i = m + n; i >= 0; i--) dbgs() << " " << u[i]); - LLVM_DEBUG(dbgs() << " by"); - LLVM_DEBUG(for (int i = n; i > 0; i--) dbgs() << " " << v[i - 1]); - LLVM_DEBUG(dbgs() << '\n'); + KNUTH_LLVM_DEBUG(dbgs() << "KnuthDiv: normal:"); + KNUTH_LLVM_DEBUG(for (int i = m + n; i >= 0; i--) dbgs() << " " << u[i]); + KNUTH_LLVM_DEBUG(dbgs() << " by"); + KNUTH_LLVM_DEBUG(for (int i = n; i > 0; i--) dbgs() << " " << v[i - 1]); + KNUTH_LLVM_DEBUG(dbgs() << '\n'); // D2. [Initialize j.] Set j to m. This is the loop counter over the places. int j = m; do { - LLVM_DEBUG(dbgs() << "KnuthDiv: quotient digit #" << j << '\n'); + KNUTH_LLVM_DEBUG(dbgs() << "KnuthDiv: quotient digit #" << j << '\n'); // D3. [Calculate q'.]. // Set qp = (u[j+n]*b + u[j+n-1]) / v[n-1]. (qp=qprime=q') // Set rp = (u[j+n]*b + u[j+n-1]) % v[n-1]. (rp=rprime=r') @@ -1321,7 +1321,8 @@ if (rp < b && (qp == b || qp*v[n-2] > b*rp + u[j+n-2])) qp--; } - LLVM_DEBUG(dbgs() << "KnuthDiv: qp == " << qp << ", rp == " << rp << '\n'); + KNUTH_LLVM_DEBUG(dbgs() + << "KnuthDiv: qp == " << qp << ", rp == " << rp << '\n'); // D4. [Multiply and subtract.] Replace (u[j+n]u[j+n-1]...u[j]) with // (u[j+n]u[j+n-1]..u[j]) - qp * (v[n-1]...v[1]v[0]). This computation @@ -1337,15 +1338,15 @@ int64_t subres = int64_t(u[j+i]) - borrow - Lo_32(p); u[j+i] = Lo_32(subres); borrow = Hi_32(p) - Hi_32(subres); - LLVM_DEBUG(dbgs() << "KnuthDiv: u[j+i] = " << u[j + i] - << ", borrow = " << borrow << '\n'); + KNUTH_LLVM_DEBUG(dbgs() << "KnuthDiv: u[j+i] = " << u[j + i] + << ", borrow = " << borrow << '\n'); } bool isNeg = u[j+n] < borrow; u[j+n] -= Lo_32(borrow); - LLVM_DEBUG(dbgs() << "KnuthDiv: after subtraction:"); - LLVM_DEBUG(for (int i = m + n; i >= 0; i--) dbgs() << " " << u[i]); - LLVM_DEBUG(dbgs() << '\n'); + KNUTH_LLVM_DEBUG(dbgs() << "KnuthDiv: after subtraction:"); + KNUTH_LLVM_DEBUG(for (int i = m + n; i >= 0; i--) dbgs() << " " << u[i]); + KNUTH_LLVM_DEBUG(dbgs() << '\n'); // D5. [Test remainder.] Set q[j] = qp. If the result of step D4 was // negative, go to step D6; otherwise go on to step D7. @@ -1366,16 +1367,16 @@ } u[j+n] += carry; } - LLVM_DEBUG(dbgs() << "KnuthDiv: after correction:"); - LLVM_DEBUG(for (int i = m + n; i >= 0; i--) dbgs() << " " << u[i]); - LLVM_DEBUG(dbgs() << "\nKnuthDiv: digit result = " << q[j] << '\n'); + KNUTH_LLVM_DEBUG(dbgs() << "KnuthDiv: after correction:"); + KNUTH_LLVM_DEBUG(for (int i = m + n; i >= 0; i--) dbgs() << " " << u[i]); + KNUTH_LLVM_DEBUG(dbgs() << "\nKnuthDiv: digit result = " << q[j] << '\n'); // D7. [Loop on j.] Decrease j by one. Now if j >= 0, go back to D3. } while (--j >= 0); - LLVM_DEBUG(dbgs() << "KnuthDiv: quotient:"); - LLVM_DEBUG(for (int i = m; i >= 0; i--) dbgs() << " " << q[i]); - LLVM_DEBUG(dbgs() << '\n'); + KNUTH_LLVM_DEBUG(dbgs() << "KnuthDiv: quotient:"); + KNUTH_LLVM_DEBUG(for (int i = m; i >= 0; i--) dbgs() << " " << q[i]); + KNUTH_LLVM_DEBUG(dbgs() << '\n'); // D8. [Unnormalize]. Now q[...] is the desired quotient, and the desired // remainder may be obtained by dividing u[...] by d. If r is non-null we @@ -1386,23 +1387,21 @@ // shift right here. if (shift) { uint32_t carry = 0; - LLVM_DEBUG(dbgs() << "KnuthDiv: remainder:"); + KNUTH_LLVM_DEBUG(dbgs() << "KnuthDiv: remainder:"); for (int i = n-1; i >= 0; i--) { r[i] = (u[i] >> shift) | carry; carry = u[i] << (32 - shift); - LLVM_DEBUG(dbgs() << " " << r[i]); + KNUTH_LLVM_DEBUG(dbgs() << " " << r[i]); } } else { for (int i = n-1; i >= 0; i--) { r[i] = u[i]; - LLVM_DEBUG(dbgs() << " " << r[i]); + KNUTH_LLVM_DEBUG(dbgs() << " " << r[i]); } } - LLVM_DEBUG(dbgs() << '\n'); + KNUTH_LLVM_DEBUG(dbgs() << '\n'); } - LLVM_DEBUG(dbgs() << '\n'); - -#pragma pop_macro("LLVM_DEBUG") + KNUTH_LLVM_DEBUG(dbgs() << '\n'); } void APInt::divide(const WordType *LHS, unsigned lhsWords, const WordType *RHS,