forked from OSchip/llvm-project
[APInt] Use trailing bit counting methods instead of population count method in isAllOnesValue, isMaxSigendValue, and isMinSignedValue. NFCI
The trailing bit methods will early out if they find a bit of the opposite while popcount must always look at all bits. I also assume that more CPUs implement trailing bit counting with native instructions than population count. llvm-svn: 306154
This commit is contained in:
parent
405165210b
commit
b73646f822
|
@ -389,7 +389,7 @@ public:
|
||||||
bool isAllOnesValue() const {
|
bool isAllOnesValue() const {
|
||||||
if (isSingleWord())
|
if (isSingleWord())
|
||||||
return U.VAL == WORD_MAX >> (APINT_BITS_PER_WORD - BitWidth);
|
return U.VAL == WORD_MAX >> (APINT_BITS_PER_WORD - BitWidth);
|
||||||
return countPopulationSlowCase() == BitWidth;
|
return countTrailingOnesSlowCase() == BitWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Determine if all bits are clear
|
/// \brief Determine if all bits are clear
|
||||||
|
@ -414,7 +414,7 @@ public:
|
||||||
/// This checks to see if the value of this APInt is the maximum signed
|
/// This checks to see if the value of this APInt is the maximum signed
|
||||||
/// value for the APInt's bit width.
|
/// value for the APInt's bit width.
|
||||||
bool isMaxSignedValue() const {
|
bool isMaxSignedValue() const {
|
||||||
return !isNegative() && countPopulation() == BitWidth - 1;
|
return !isNegative() && countTrailingOnes() == BitWidth - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Determine if this is the smallest unsigned value.
|
/// \brief Determine if this is the smallest unsigned value.
|
||||||
|
@ -428,7 +428,7 @@ public:
|
||||||
/// This checks to see if the value of this APInt is the minimum signed
|
/// This checks to see if the value of this APInt is the minimum signed
|
||||||
/// value for the APInt's bit width.
|
/// value for the APInt's bit width.
|
||||||
bool isMinSignedValue() const {
|
bool isMinSignedValue() const {
|
||||||
return isNegative() && isPowerOf2();
|
return isNegative() && countTrailingZeros() == BitWidth - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Check if this APInt has an N-bits unsigned integer value.
|
/// \brief Check if this APInt has an N-bits unsigned integer value.
|
||||||
|
|
Loading…
Reference in New Issue