mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-20 03:23:01 +02:00
[block-freq] Add the APInt method extractBit.
llvm-svn: 197271
This commit is contained in:
parent
95fe9491c9
commit
7ed19350c0
@ -1244,6 +1244,9 @@ 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
|
||||||
/// @{
|
/// @{
|
||||||
|
@ -607,6 +607,14 @@ 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 ||
|
||||||
|
@ -597,4 +597,30 @@ TEST(APIntTest, tcDecrement) {
|
|||||||
EXPECT_EQ(APInt::tcCompare(test, expected, 4), 0);
|
EXPECT_EQ(APInt::tcCompare(test, expected, 4), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(APIntTest, extractBit) {
|
||||||
|
// Single word check.
|
||||||
|
uint64_t E1 = 0x2CA7F46BF6569915ULL;
|
||||||
|
APInt A1(64, E1);
|
||||||
|
for (unsigned i = 0, e = 64; i < e; ++i) {
|
||||||
|
EXPECT_EQ(bool(E1 & (1ULL << i)),
|
||||||
|
A1.extractBit(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multiword check.
|
||||||
|
integerPart E2[4] = {
|
||||||
|
0xeb6eb136591cba21ULL,
|
||||||
|
0x7b9358bd6a33f10aULL,
|
||||||
|
0x7e7ffa5eadd8846ULL,
|
||||||
|
0x305f341ca00b613dULL
|
||||||
|
};
|
||||||
|
APInt A2(integerPartWidth*4, ArrayRef<integerPart>(E2, 4));
|
||||||
|
for (unsigned i = 0; i < 4; ++i) {
|
||||||
|
for (unsigned j = 0; j < integerPartWidth; ++j) {
|
||||||
|
EXPECT_EQ(bool(E2[i] & (1ULL << j)),
|
||||||
|
A2.extractBit(i*integerPartWidth + j));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user