Added log2 for log-base-2 and also modified IsPower2 to use it.

llvm-svn: 2653
This commit is contained in:
Vikram S. Adve 2002-05-19 15:46:52 +00:00
parent 18d5a88024
commit e363307e49
1 changed files with 15 additions and 9 deletions

View File

@ -12,21 +12,27 @@
#ifndef LLVM_SUPPORT_MATH_EXTRAS_H #ifndef LLVM_SUPPORT_MATH_EXTRAS_H
#define LLVM_SUPPORT_MATH_EXTRAS_H #define LLVM_SUPPORT_MATH_EXTRAS_H
#include <sys/types.h> #include <Support/DataTypes.h>
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 inline bool
bool IsPowerOf2(int64_t C, unsigned& getPow) IsPowerOf2(int64_t C, unsigned& getPow)
{ {
if (C < 0) if (C < 0)
C = -C; C = -C;
bool isBool = C > 0 && (C == (C & ~(C - 1))); bool isPowerOf2 = C > 0 && (C == (C & ~(C - 1)));
if (isBool) if (isPowerOf2)
for (getPow = 0; C > 1; getPow++) getPow = log2(C);
C = C >> 1;
return isBool; return isPowerOf2;
} }
#endif /*LLVM_SUPPORT_MATH_EXTRAS_H*/ #endif /*LLVM_SUPPORT_MATH_EXTRAS_H*/