/// This function returns the high "numBits" bits of this APInt.
APInt APInt::getHiBits(unsigned numBits) const {
- return APIntOps::lshr(*this, BitWidth - numBits);
+ return this->lshr(BitWidth - numBits);
}
/// This function returns the low "numBits" bits of this APInt.
APInt APInt::getLoBits(unsigned numBits) const {
- return APIntOps::lshr(APIntOps::shl(*this, BitWidth - numBits),
- BitWidth - numBits);
+ APInt Result(getLowBitsSet(BitWidth, numBits));
+ Result &= *this;
+ return Result;
}
unsigned APInt::countLeadingZerosSlowCase() const {
EXPECT_EQ(128u, i128.countTrailingOnes());
EXPECT_EQ(128u, i128.countPopulation());
}
+
+TEST(APIntTest, getLoBits) {
+ APInt i32(32, 0xfa);
+ i32.setHighBits(1);
+ EXPECT_EQ(0xa, i32.getLoBits(4));
+ APInt i128(128, 0xfa);
+ i128.setHighBits(1);
+ EXPECT_EQ(0xa, i128.getLoBits(4));
+}
+
+TEST(APIntTest, getHiBits) {
+ APInt i32(32, 0xfa);
+ i32.setHighBits(2);
+ EXPECT_EQ(0xc, i32.getHiBits(4));
+ APInt i128(128, 0xfa);
+ i128.setHighBits(2);
+ EXPECT_EQ(0xc, i128.getHiBits(4));
+}