Added log2 for log-base-2 and also modified IsPower2 to use it.
authorVikram S. Adve <vadve@cs.uiuc.edu>
Sun, 19 May 2002 15:46:52 +0000 (15:46 +0000)
committerVikram S. Adve <vadve@cs.uiuc.edu>
Sun, 19 May 2002 15:46:52 +0000 (15:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2653 91177308-0d34-0410-b5e6-96231b3b80d8

include/Support/MathExtras.h
include/llvm/Support/MathExtras.h

index f3dc3de17bbcec914ef59d761ea5196904ad37ba..9fbb827a439113cf7bbd3fba02bb86360482b095 100644 (file)
 #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*/
index f3dc3de17bbcec914ef59d761ea5196904ad37ba..9fbb827a439113cf7bbd3fba02bb86360482b095 100644 (file)
 #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*/