aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/ADT/APInt.h
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 /include/llvm/ADT/APInt.h
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 'include/llvm/ADT/APInt.h')
-rw-r--r--include/llvm/ADT/APInt.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h
index 6c418bd..88aa995 100644
--- a/include/llvm/ADT/APInt.h
+++ b/include/llvm/ADT/APInt.h
@@ -1234,6 +1234,11 @@ public:
return BitWidth - 1 - countLeadingZeros();
}
+ /// @returns the ceil log base 2 of this APInt.
+ unsigned ceilLogBase2() const {
+ return BitWidth - (*this - 1).countLeadingZeros();
+ }
+
/// @returns the log base 2 of this APInt if its an exact power of two, -1
/// otherwise
int32_t exactLogBase2() const {