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 | 1050ec5cc42c4b1ff1702e09da9d520abe205b0d (patch) | |
tree | f81fd31f5fcaf4a73af9e781e5f04bd82d52a798 /lib | |
parent | 5bce8547f3ebad55611bfc74f1be0437287fa319 (diff) | |
download | external_llvm-1050ec5cc42c4b1ff1702e09da9d520abe205b0d.zip external_llvm-1050ec5cc42c4b1ff1702e09da9d520abe205b0d.tar.gz external_llvm-1050ec5cc42c4b1ff1702e09da9d520abe205b0d.tar.bz2 |
Fix the remainder shifting in KnuthDiv.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34562 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Support/APInt.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp index 7f2aa42..60c940c 100644 --- a/lib/Support/APInt.cpp +++ b/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'); } |