diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-02-21 00:29:48 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-02-21 00:29:48 +0000 |
commit | 74cf82e5221f9c0010910cd8da563addfadf9948 (patch) | |
tree | 73f39ada2d0511bf86bed740b897327656c0c106 /llvm/lib/Support/APInt.cpp | |
parent | 7a6a8d5116d0dfe5ce9e5c5b3585c4e164fd80a2 (diff) | |
download | bcm5719-llvm-74cf82e5221f9c0010910cd8da563addfadf9948.tar.gz bcm5719-llvm-74cf82e5221f9c0010910cd8da563addfadf9948.zip |
Fix countLeadingZeros to actually return the correct number.
Fix toString to correctly return "0" for zero valued APInts over 128 bits.
llvm-svn: 34459
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 9dca64085c5..4bb9ff749e6 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -696,18 +696,20 @@ bool APInt::isPowerOf2() const { /// the number of zeros from the most significant bit to the first one bit. /// @returns numWord() * 64 if the value is zero. uint32_t APInt::countLeadingZeros() const { - if (isSingleWord()) - return CountLeadingZeros_64(VAL) - (APINT_BITS_PER_WORD - BitWidth); uint32_t Count = 0; - for (uint32_t i = getNumWords(); i > 0u; --i) { - uint32_t tmp = CountLeadingZeros_64(pVal[i-1]); - Count += tmp; - if (tmp != APINT_BITS_PER_WORD) - if (i == getNumWords()) - Count -= (APINT_BITS_PER_WORD - whichBit(BitWidth)); - break; + if (isSingleWord()) + Count = CountLeadingZeros_64(VAL); + else { + for (uint32_t i = getNumWords(); i > 0u; --i) { + if (pVal[i-1] == 0) + Count += APINT_BITS_PER_WORD; + else { + Count += CountLeadingZeros_64(pVal[i-1]); + break; + } + } } - return Count; + return Count - (APINT_BITS_PER_WORD - (BitWidth % APINT_BITS_PER_WORD)); } /// countTrailingZeros - This function is a APInt version corresponding to @@ -1513,7 +1515,7 @@ std::string APInt::toString(uint8_t radix, bool wantSigned) const { result = "-"; insert_at = 1; } - if (tmp == 0) + if (tmp == APInt(tmp.getBitWidth(), 0)) result = "0"; else while (tmp.ne(zero)) { APInt APdigit(1,0); |