summaryrefslogtreecommitdiffstats
path: root/llvm/include/Support
diff options
context:
space:
mode:
authorVikram S. Adve <vadve@cs.uiuc.edu>2002-05-19 15:46:52 +0000
committerVikram S. Adve <vadve@cs.uiuc.edu>2002-05-19 15:46:52 +0000
commite363307e49b09831063c09c428a069200cce8246 (patch)
treea2bdb2f8f2937cbdf51de63b20bc728c53e11038 /llvm/include/Support
parent18d5a880241a79e7dff8129638ca07f694b77720 (diff)
downloadbcm5719-llvm-e363307e49b09831063c09c428a069200cce8246.tar.gz
bcm5719-llvm-e363307e49b09831063c09c428a069200cce8246.zip
Added log2 for log-base-2 and also modified IsPower2 to use it.
llvm-svn: 2653
Diffstat (limited to 'llvm/include/Support')
-rw-r--r--llvm/include/Support/MathExtras.h24
1 files changed, 15 insertions, 9 deletions
diff --git a/llvm/include/Support/MathExtras.h b/llvm/include/Support/MathExtras.h
index f3dc3de17bb..9fbb827a439 100644
--- a/llvm/include/Support/MathExtras.h
+++ b/llvm/include/Support/MathExtras.h
@@ -12,21 +12,27 @@
#ifndef 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
-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*/
OpenPOWER on IntegriCloud