Regularize the names of #include-guards.
[oota-llvm.git] / include / llvm / Support / MathExtras.h
1 //===-- Support/MathExtras.h - Useful math functions -------------*- C++ -*--=//
2 //
3 // This file contains some functions that are useful for math stuff.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #ifndef SUPPORT_MATHEXTRAS_H
8 #define SUPPORT_MATHEXTRAS_H
9
10 #include "Support/DataTypes.h"
11
12 inline unsigned log2(uint64_t C) {
13   unsigned getPow;
14   for (getPow = 0; C > 1; ++getPow)
15     C >>= 1;
16   return getPow;
17 }
18
19 inline bool isPowerOf2(int64_t C, unsigned &getPow) {
20   if (C < 0) C = -C;
21   if (C > 0 && C == (C & ~(C - 1))) {
22     getPow = log2((uint64_t)C);
23     return true;
24   }
25
26   return false;
27 }
28
29 #endif