Added LLVM notice.
[oota-llvm.git] / include / llvm / Support / MathExtras.h
1 //===-- Support/MathExtras.h - Useful math functions ------------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains some functions that are useful for math stuff.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef SUPPORT_MATHEXTRAS_H
15 #define SUPPORT_MATHEXTRAS_H
16
17 #include "Support/DataTypes.h"
18
19 inline unsigned log2(uint64_t C) {
20   unsigned getPow;
21   for (getPow = 0; C > 1; ++getPow)
22     C >>= 1;
23   return getPow;
24 }
25
26 inline bool isPowerOf2(int64_t C, unsigned &getPow) {
27   if (C < 0) C = -C;
28   if (C > 0 && C == (C & ~(C - 1))) {
29     getPow = log2((uint64_t)C);
30     return true;
31   }
32
33   return false;
34 }
35
36 #endif