From: Vikram S. Adve Date: Sun, 19 May 2002 15:46:52 +0000 (+0000) Subject: Added log2 for log-base-2 and also modified IsPower2 to use it. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=bcfa423e3d1a2a385b56e3ec0f03137f0c33efc7;p=oota-llvm.git Added log2 for log-base-2 and also modified IsPower2 to use it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2653 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/Support/MathExtras.h b/include/Support/MathExtras.h index f3dc3de17bb..9fbb827a439 100644 --- a/include/Support/MathExtras.h +++ b/include/Support/MathExtras.h @@ -12,21 +12,27 @@ #ifndef LLVM_SUPPORT_MATH_EXTRAS_H #define LLVM_SUPPORT_MATH_EXTRAS_H -#include +#include -inline bool IsPowerOf2 (int64_t C, unsigned& getPow); +inline unsigned +log2(uint64_t C) +{ + unsigned getPow; + for (getPow = 0; C > 1; getPow++) + C = C >> 1; + return getPow; +} -inline -bool IsPowerOf2(int64_t C, unsigned& getPow) +inline bool +IsPowerOf2(int64_t C, unsigned& getPow) { if (C < 0) C = -C; - bool isBool = C > 0 && (C == (C & ~(C - 1))); - if (isBool) - for (getPow = 0; C > 1; getPow++) - C = C >> 1; + bool isPowerOf2 = C > 0 && (C == (C & ~(C - 1))); + if (isPowerOf2) + getPow = log2(C); - return isBool; + return isPowerOf2; } #endif /*LLVM_SUPPORT_MATH_EXTRAS_H*/ diff --git a/include/llvm/Support/MathExtras.h b/include/llvm/Support/MathExtras.h index f3dc3de17bb..9fbb827a439 100644 --- a/include/llvm/Support/MathExtras.h +++ b/include/llvm/Support/MathExtras.h @@ -12,21 +12,27 @@ #ifndef LLVM_SUPPORT_MATH_EXTRAS_H #define LLVM_SUPPORT_MATH_EXTRAS_H -#include +#include -inline bool IsPowerOf2 (int64_t C, unsigned& getPow); +inline unsigned +log2(uint64_t C) +{ + unsigned getPow; + for (getPow = 0; C > 1; getPow++) + C = C >> 1; + return getPow; +} -inline -bool IsPowerOf2(int64_t C, unsigned& getPow) +inline bool +IsPowerOf2(int64_t C, unsigned& getPow) { if (C < 0) C = -C; - bool isBool = C > 0 && (C == (C & ~(C - 1))); - if (isBool) - for (getPow = 0; C > 1; getPow++) - C = C >> 1; + bool isPowerOf2 = C > 0 && (C == (C & ~(C - 1))); + if (isPowerOf2) + getPow = log2(C); - return isBool; + return isPowerOf2; } #endif /*LLVM_SUPPORT_MATH_EXTRAS_H*/