diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-02-17 22:38:07 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-02-17 22:38:07 +0000 |
commit | 26c6616e4ba36aec9b9d0718ffa8e437e699a353 (patch) | |
tree | 14f7254587e7155c97bd282796ccf4461bc530d8 /llvm/lib/Support/APInt.cpp | |
parent | 2605082f0e9a694a380b4b1b6efff84028529beb (diff) | |
download | bcm5719-llvm-26c6616e4ba36aec9b9d0718ffa8e437e699a353.tar.gz bcm5719-llvm-26c6616e4ba36aec9b9d0718ffa8e437e699a353.zip |
Fix some bugs in division logic.
llvm-svn: 34384
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 211bf90d8cf..69cbdc7a35e 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -980,7 +980,7 @@ static unsigned subMul(unsigned dest[], unsigned offset, unsigned carry = 0; unsigned j = 0; do { - uint64_t prod = ((uint64_t) x[j] & 0xffffffffL) * yl; + uint64_t prod = ((uint64_t) x[j] & 0xffffffffUL) * yl; unsigned prod_low = (unsigned) prod; unsigned prod_high = (unsigned) (prod >> 32); prod_low += carry; @@ -1104,7 +1104,8 @@ APInt APInt::udiv(const APInt& RHS) const { X = APIntOps::shl(Result, nshift); ++lhsWords; } - div((unsigned*)X.pVal, lhsWords * 2 - 1, (unsigned*)Y.pVal, rhsWords*2); + div((unsigned*)X.pVal, lhsWords * 2 - 1, + (unsigned*)(Y.isSingleWord()? &Y.VAL : Y.pVal), rhsWords*2); memset(Result.pVal, 0, Result.getNumWords() * 8); memcpy(Result.pVal, X.pVal + rhsWords, (lhsWords - rhsWords) * 8); } @@ -1154,7 +1155,8 @@ APInt APInt::urem(const APInt& RHS) const { APIntOps::shl(Y, nshift); APIntOps::shl(X, nshift); } - div((unsigned*)X.pVal, rhsWords*2-1, (unsigned*)Y.pVal, rhsWords*2); + div((unsigned*)X.pVal, rhsWords*2-1, + (unsigned*)(Y.isSingleWord()? &Y.VAL : Y.pVal), rhsWords*2); memset(Result.pVal, 0, Result.getNumWords() * 8); for (unsigned i = 0; i < rhsWords-1; ++i) Result.pVal[i] = (X.pVal[i] >> nshift) | (X.pVal[i+1] << (64 - nshift)); |