2004-09-01 22:55:40 +00:00
|
|
|
//===-- llvm/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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-11-27 00:03:19 +00:00
|
|
|
|
2004-09-01 22:55:40 +00:00
|
|
|
#ifndef LLVM_SUPPORT_MATHEXTRAS_H
|
|
|
|
#define LLVM_SUPPORT_MATHEXTRAS_H
|
2001-11-27 00:03:19 +00:00
|
|
|
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2001-11-27 00:03:19 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2004-02-25 01:53:45 +00:00
|
|
|
#if defined(log2)
|
|
|
|
# undef log2
|
|
|
|
#endif
|
|
|
|
|
2002-05-19 21:19:55 +00:00
|
|
|
inline unsigned log2(uint64_t C) {
|
2002-05-19 15:46:52 +00:00
|
|
|
unsigned getPow;
|
2002-05-19 21:19:55 +00:00
|
|
|
for (getPow = 0; C > 1; ++getPow)
|
|
|
|
C >>= 1;
|
2002-05-19 15:46:52 +00:00
|
|
|
return getPow;
|
|
|
|
}
|
2001-11-27 00:03:19 +00:00
|
|
|
|
2004-08-17 19:17:10 +00:00
|
|
|
inline unsigned log2(unsigned C) {
|
|
|
|
unsigned getPow;
|
|
|
|
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;
|
2001-11-27 00:03:19 +00:00
|
|
|
}
|
|
|
|
|
2004-06-23 00:25:24 +00:00
|
|
|
// Platform-independent wrappers for the C99 isnan() function.
|
|
|
|
int IsNAN (float f);
|
|
|
|
int IsNAN (double d);
|
|
|
|
|
2004-07-21 03:15:14 +00:00
|
|
|
// Platform-independent wrappers for the C99 isinf() function.
|
|
|
|
int IsInf (float f);
|
|
|
|
int IsInf (double d);
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2002-05-19 21:19:55 +00:00
|
|
|
#endif
|