forked from OSchip/llvm-project
Remove APInt::extractBit since it is already implemented via operator[]. Change tests for extractBit to test operator[].
llvm-svn: 197277
This commit is contained in:
parent
a8df53f4ad
commit
e1fad2b560
|
@ -1244,9 +1244,6 @@ public:
|
||||||
/// as "bitPosition".
|
/// as "bitPosition".
|
||||||
void flipBit(unsigned bitPosition);
|
void flipBit(unsigned bitPosition);
|
||||||
|
|
||||||
/// \brief Returns true if the bit in bitPosition is set.
|
|
||||||
bool extractBit(unsigned bitPosition) const;
|
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
/// \name Value Characterization Functions
|
/// \name Value Characterization Functions
|
||||||
/// @{
|
/// @{
|
||||||
|
@ -1517,7 +1514,7 @@ public:
|
||||||
// UINT32_MAX. Finally extractBit of MSB - 1 will be UINT32_MAX implying
|
// UINT32_MAX. Finally extractBit of MSB - 1 will be UINT32_MAX implying
|
||||||
// that we get BitWidth - 1.
|
// that we get BitWidth - 1.
|
||||||
unsigned lg = logBase2();
|
unsigned lg = logBase2();
|
||||||
return lg + unsigned(extractBit(std::min(lg - 1, BitWidth - 1)));
|
return lg + unsigned((*this)[std::min(lg - 1, BitWidth - 1)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \returns the log base 2 of this APInt if its an exact power of two, -1
|
/// \returns the log base 2 of this APInt if its an exact power of two, -1
|
||||||
|
|
|
@ -607,14 +607,6 @@ void APInt::flipBit(unsigned bitPosition) {
|
||||||
else setBit(bitPosition);
|
else setBit(bitPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool APInt::extractBit(unsigned bitPosition) const {
|
|
||||||
assert(bitPosition < BitWidth && "Out of the bit-width range!");
|
|
||||||
if (isSingleWord())
|
|
||||||
return VAL & maskBit(bitPosition);
|
|
||||||
else
|
|
||||||
return pVal[whichWord(bitPosition)] & maskBit(bitPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned APInt::getBitsNeeded(StringRef str, uint8_t radix) {
|
unsigned APInt::getBitsNeeded(StringRef str, uint8_t radix) {
|
||||||
assert(!str.empty() && "Invalid string length");
|
assert(!str.empty() && "Invalid string length");
|
||||||
assert((radix == 10 || radix == 8 || radix == 16 || radix == 2 ||
|
assert((radix == 10 || radix == 8 || radix == 16 || radix == 2 ||
|
||||||
|
|
|
@ -598,13 +598,13 @@ TEST(APIntTest, tcDecrement) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(APIntTest, extractBit) {
|
TEST(APIntTest, arrayAccess) {
|
||||||
// Single word check.
|
// Single word check.
|
||||||
uint64_t E1 = 0x2CA7F46BF6569915ULL;
|
uint64_t E1 = 0x2CA7F46BF6569915ULL;
|
||||||
APInt A1(64, E1);
|
APInt A1(64, E1);
|
||||||
for (unsigned i = 0, e = 64; i < e; ++i) {
|
for (unsigned i = 0, e = 64; i < e; ++i) {
|
||||||
EXPECT_EQ(bool(E1 & (1ULL << i)),
|
EXPECT_EQ(bool(E1 & (1ULL << i)),
|
||||||
A1.extractBit(i));
|
A1[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multiword check.
|
// Multiword check.
|
||||||
|
@ -618,7 +618,7 @@ TEST(APIntTest, extractBit) {
|
||||||
for (unsigned i = 0; i < 4; ++i) {
|
for (unsigned i = 0; i < 4; ++i) {
|
||||||
for (unsigned j = 0; j < integerPartWidth; ++j) {
|
for (unsigned j = 0; j < integerPartWidth; ++j) {
|
||||||
EXPECT_EQ(bool(E2[i] & (1ULL << j)),
|
EXPECT_EQ(bool(E2[i] & (1ULL << j)),
|
||||||
A2.extractBit(i*integerPartWidth + j));
|
A2[i*integerPartWidth + j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue