Files
llvm/include/Support/MathExtras.h
T

45 lines
1.0 KiB
C++
Raw Normal View History

2003-09-30 18:37:50 +00:00
//===-- Support/MathExtras.h - Useful math functions ------------*- C++ -*-===//
2003-10-20 19:46:57 +00:00
//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
2002-05-19 21:19:55 +00:00
//
// This file contains some functions that are useful for math stuff.
//
//===----------------------------------------------------------------------===//
2003-06-17 00:35:55 +00:00
#ifndef SUPPORT_MATHEXTRAS_H
#define SUPPORT_MATHEXTRAS_H
#include "Support/DataTypes.h"
namespace llvm {
#if defined(log2)
# undef log2
#endif
2002-05-19 21:19:55 +00:00
inline unsigned log2(uint64_t C) {
unsigned getPow;
2002-05-19 21:19:55 +00:00
for (getPow = 0; C > 1; ++getPow)
C >>= 1;
return getPow;
}
2002-05-19 21:19:55 +00:00
inline bool isPowerOf2(int64_t C, unsigned &getPow) {
if (C < 0) C = -C;
if (C > 0 && C == (C & ~(C - 1))) {
2003-11-16 20:21:15 +00:00
getPow = log2(static_cast<uint64_t>(C));
2002-05-19 21:19:55 +00:00
return true;
}
return false;
}
} // End llvm namespace
2002-05-19 21:19:55 +00:00
#endif