diff options
author | Dan Gohman <gohman@apple.com> | 2009-10-13 01:49:02 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-10-13 01:49:02 +0000 |
commit | bbf0a780e9c94afc562bafbb40ea0afd6377000f (patch) | |
tree | 7658fbbdc579a3674ef2261cc546986c5f3dcff4 /include/llvm | |
parent | 1fc5fb659c7acd0415e6f7b02393179303071982 (diff) | |
download | external_llvm-bbf0a780e9c94afc562bafbb40ea0afd6377000f.tar.gz external_llvm-bbf0a780e9c94afc562bafbb40ea0afd6377000f.tar.bz2 external_llvm-bbf0a780e9c94afc562bafbb40ea0afd6377000f.zip |
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')
-rw-r--r-- | include/llvm/ADT/APInt.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index 6c418bda62..88aa9956d9 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 { |