mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-21 18:24:23 +00:00
MathExtras: Bring Count(Trailing|Leading)Ones and CountPopulation in line with countTrailingZeros
Update all callers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228930 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -124,25 +124,15 @@ public:
|
||||
size_type count() const {
|
||||
unsigned NumBits = 0;
|
||||
for (unsigned i = 0; i < BITWORDS_PER_ELEMENT; ++i)
|
||||
if (sizeof(BitWord) == 4)
|
||||
NumBits += CountPopulation_32(Bits[i]);
|
||||
else if (sizeof(BitWord) == 8)
|
||||
NumBits += CountPopulation_64(Bits[i]);
|
||||
else
|
||||
llvm_unreachable("Unsupported!");
|
||||
NumBits += countPopulation(Bits[i]);
|
||||
return NumBits;
|
||||
}
|
||||
|
||||
/// find_first - Returns the index of the first set bit.
|
||||
int find_first() const {
|
||||
for (unsigned i = 0; i < BITWORDS_PER_ELEMENT; ++i)
|
||||
if (Bits[i] != 0) {
|
||||
if (sizeof(BitWord) == 4)
|
||||
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
|
||||
if (sizeof(BitWord) == 8)
|
||||
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
|
||||
llvm_unreachable("Unsupported!");
|
||||
}
|
||||
if (Bits[i] != 0)
|
||||
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
|
||||
llvm_unreachable("Illegal empty element");
|
||||
}
|
||||
|
||||
@ -161,23 +151,13 @@ public:
|
||||
// Mask off previous bits.
|
||||
Copy &= ~0UL << BitPos;
|
||||
|
||||
if (Copy != 0) {
|
||||
if (sizeof(BitWord) == 4)
|
||||
return WordPos * BITWORD_SIZE + countTrailingZeros(Copy);
|
||||
if (sizeof(BitWord) == 8)
|
||||
return WordPos * BITWORD_SIZE + countTrailingZeros(Copy);
|
||||
llvm_unreachable("Unsupported!");
|
||||
}
|
||||
if (Copy != 0)
|
||||
return WordPos * BITWORD_SIZE + countTrailingZeros(Copy);
|
||||
|
||||
// Check subsequent words.
|
||||
for (unsigned i = WordPos+1; i < BITWORDS_PER_ELEMENT; ++i)
|
||||
if (Bits[i] != 0) {
|
||||
if (sizeof(BitWord) == 4)
|
||||
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
|
||||
if (sizeof(BitWord) == 8)
|
||||
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
|
||||
llvm_unreachable("Unsupported!");
|
||||
}
|
||||
if (Bits[i] != 0)
|
||||
return i * BITWORD_SIZE + countTrailingZeros(Bits[i]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user