diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-02-24 20:38:01 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-02-24 20:38:01 +0000 |
commit | 468ad911cbeb52c99d613e8891154099a3f457f5 (patch) | |
tree | b090cc396a11928e23da9610f9add004d956a981 /llvm/lib/Support/APInt.cpp | |
parent | 632ebdf8bda287f344d979b2072627164cd12a88 (diff) | |
download | bcm5719-llvm-468ad911cbeb52c99d613e8891154099a3f457f5.tar.gz bcm5719-llvm-468ad911cbeb52c99d613e8891154099a3f457f5.zip |
Fix the remainder shifting in KnuthDiv.
llvm-svn: 34562
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 7f2aa429247..60c940c566d 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -1134,12 +1134,19 @@ static void KnuthDiv(uint32_t *u, uint32_t *v, uint32_t *q, uint32_t* r, // The value d is expressed by the "shift" value above since we avoided // multiplication by d by using a shift left. So, all we have to do is // shift right here. In order to mak - uint32_t carry = 0; - DEBUG(cerr << "KnuthDiv: remainder:"); - for (int i = n-1; i >= 0; i--) { - r[i] = (u[i] >> shift) | carry; - carry = u[i] << shift; - DEBUG(cerr << " " << r[i]); + if (shift) { + uint32_t carry = 0; + DEBUG(cerr << "KnuthDiv: remainder:"); + for (int i = n-1; i >= 0; i--) { + r[i] = (u[i] >> shift) | carry; + carry = u[i] << (32 - shift); + DEBUG(cerr << " " << r[i]); + } + } else { + for (int i = n-1; i >= 0; i--) { + r[i] = u[i]; + DEBUG(cerr << " " << r[i]); + } } DEBUG(cerr << '\n'); } |