aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/ADT
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-10-13 01:49:02 +0000
committerDan Gohman <gohman@apple.com>2009-10-13 01:49:02 +0000
commitcbc7cc63b6c7ee1008f92064388c37327c183328 (patch)
tree7658fbbdc579a3674ef2261cc546986c5f3dcff4 /unittests/ADT
parent5c78736f85579aa6de38cba2742ea13ff9f79e70 (diff)
downloadexternal_llvm-cbc7cc63b6c7ee1008f92064388c37327c183328.zip
external_llvm-cbc7cc63b6c7ee1008f92064388c37327c183328.tar.gz
external_llvm-cbc7cc63b6c7ee1008f92064388c37327c183328.tar.bz2
Add a ceilLogBase2 function to APInt.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83932 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ADT')
-rw-r--r--unittests/ADT/APIntTest.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/unittests/ADT/APIntTest.cpp b/unittests/ADT/APIntTest.cpp
index 24a3d9b..7b03d0f 100644
--- a/unittests/ADT/APIntTest.cpp
+++ b/unittests/ADT/APIntTest.cpp
@@ -315,6 +315,17 @@ TEST(APIntTest, StringBitsNeeded16) {
EXPECT_EQ(9U, APInt::getBitsNeeded("-20", 16));
}
+TEST(APIntTest, Log2) {
+ EXPECT_EQ(APInt(15, 7).logBase2(), 2);
+ EXPECT_EQ(APInt(15, 7).ceilLogBase2(), 3);
+ EXPECT_EQ(APInt(15, 7).exactLogBase2(), -1);
+ EXPECT_EQ(APInt(15, 8).logBase2(), 3);
+ EXPECT_EQ(APInt(15, 8).ceilLogBase2(), 3);
+ EXPECT_EQ(APInt(15, 8).exactLogBase2(), 3);
+ EXPECT_EQ(APInt(15, 9).logBase2(), 3);
+ EXPECT_EQ(APInt(15, 9).ceilLogBase2(), 4);
+ EXPECT_EQ(APInt(15, 9).exactLogBase2(), -1);
+}
#ifdef GTEST_HAS_DEATH_TEST
TEST(APIntTest, StringDeath) {