[APInt] Fix nearestLogBase2 to return correct answers for very large APInt and APInt with a bitwidth of 1.

I also improved the comments, added some more tests, etc.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199610 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael Gottesman
2014-01-19 20:33:48 +00:00
parent e7413972a4
commit 7320de5ce2
2 changed files with 34 additions and 7 deletions

View File

@@ -665,6 +665,17 @@ TEST(APIntTest, nearestLogBase2) {
uint64_t I6[4] = {0x0, 0x0, 0x0, 0x18};
APInt A6(integerPartWidth*4, ArrayRef<integerPart>(I6, 4));
EXPECT_EQ(A6.nearestLogBase2(), A6.ceilLogBase2());
// Test BitWidth == 1 special cases.
APInt A7(1, 1);
EXPECT_EQ(A7.nearestLogBase2(), 0ULL);
APInt A8(1, 0);
EXPECT_EQ(A8.nearestLogBase2(), UINT32_MAX);
// Test the zero case when we have a bit width large enough such
// that the bit width is larger than UINT32_MAX-1.
APInt A9(UINT32_MAX, 0);
EXPECT_EQ(A9.nearestLogBase2(), UINT32_MAX);
}
}