From cbc7cc63b6c7ee1008f92064388c37327c183328 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 13 Oct 2009 01:49:02 +0000 Subject: Add a ceilLogBase2 function to APInt. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83932 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/APInt.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include/llvm/ADT/APInt.h') 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 { -- cgit v1.1