mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-02 07:32:52 +00:00
Fix countLeadingZeros to actually return the correct number.
Fix toString to correctly return "0" for zero valued APInts over 128 bits. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34459 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
54362ca095
commit
e549c4940c
@ -696,18 +696,20 @@ bool APInt::isPowerOf2() const {
|
|||||||
/// the number of zeros from the most significant bit to the first one bit.
|
/// the number of zeros from the most significant bit to the first one bit.
|
||||||
/// @returns numWord() * 64 if the value is zero.
|
/// @returns numWord() * 64 if the value is zero.
|
||||||
uint32_t APInt::countLeadingZeros() const {
|
uint32_t APInt::countLeadingZeros() const {
|
||||||
if (isSingleWord())
|
|
||||||
return CountLeadingZeros_64(VAL) - (APINT_BITS_PER_WORD - BitWidth);
|
|
||||||
uint32_t Count = 0;
|
uint32_t Count = 0;
|
||||||
for (uint32_t i = getNumWords(); i > 0u; --i) {
|
if (isSingleWord())
|
||||||
uint32_t tmp = CountLeadingZeros_64(pVal[i-1]);
|
Count = CountLeadingZeros_64(VAL);
|
||||||
Count += tmp;
|
else {
|
||||||
if (tmp != APINT_BITS_PER_WORD)
|
for (uint32_t i = getNumWords(); i > 0u; --i) {
|
||||||
if (i == getNumWords())
|
if (pVal[i-1] == 0)
|
||||||
Count -= (APINT_BITS_PER_WORD - whichBit(BitWidth));
|
Count += APINT_BITS_PER_WORD;
|
||||||
break;
|
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
|
/// countTrailingZeros - This function is a APInt version corresponding to
|
||||||
@ -1513,7 +1515,7 @@ std::string APInt::toString(uint8_t radix, bool wantSigned) const {
|
|||||||
result = "-";
|
result = "-";
|
||||||
insert_at = 1;
|
insert_at = 1;
|
||||||
}
|
}
|
||||||
if (tmp == 0)
|
if (tmp == APInt(tmp.getBitWidth(), 0))
|
||||||
result = "0";
|
result = "0";
|
||||||
else while (tmp.ne(zero)) {
|
else while (tmp.ne(zero)) {
|
||||||
APInt APdigit(1,0);
|
APInt APdigit(1,0);
|
||||||
|
Loading…
Reference in New Issue
Block a user