mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-01 15:17:25 +00:00
Make APInt::countLeadingZerosSlowCase() treat the contents of padding bits
as undefined. Fixes an assertion in APFloat::toString noticed by Dale. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95196 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -767,8 +767,23 @@ bool APInt::isPowerOf2() const {
|
||||
}
|
||||
|
||||
unsigned APInt::countLeadingZerosSlowCase() const {
|
||||
unsigned Count = 0;
|
||||
for (unsigned i = getNumWords(); i > 0u; --i) {
|
||||
// Treat the most significand word differently because it might have
|
||||
// meaningless bits set beyond the precision.
|
||||
unsigned BitsInMSW = BitWidth % APINT_BITS_PER_WORD;
|
||||
integerPart MSWMask;
|
||||
if (BitsInMSW) MSWMask = (integerPart(1) << BitsInMSW) - 1;
|
||||
else {
|
||||
MSWMask = ~integerPart(0);
|
||||
BitsInMSW = APINT_BITS_PER_WORD;
|
||||
}
|
||||
|
||||
unsigned i = getNumWords();
|
||||
integerPart MSW = pVal[i-1] & MSWMask;
|
||||
if (MSW)
|
||||
return CountLeadingZeros_64(MSW) - (APINT_BITS_PER_WORD - BitsInMSW);
|
||||
|
||||
unsigned Count = BitsInMSW;
|
||||
for (--i; i > 0u; --i) {
|
||||
if (pVal[i-1] == 0)
|
||||
Count += APINT_BITS_PER_WORD;
|
||||
else {
|
||||
@@ -776,10 +791,7 @@ unsigned APInt::countLeadingZerosSlowCase() const {
|
||||
break;
|
||||
}
|
||||
}
|
||||
unsigned remainder = BitWidth % APINT_BITS_PER_WORD;
|
||||
if (remainder)
|
||||
Count -= APINT_BITS_PER_WORD - remainder;
|
||||
return std::min(Count, BitWidth);
|
||||
return Count;
|
||||
}
|
||||
|
||||
static unsigned countLeadingOnes_64(uint64_t V, unsigned skip) {
|
||||
|
||||
Reference in New Issue
Block a user