X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FSupport%2FMathExtras.h;h=9c5f32cd5ff2fc27534a702bd00842cdf66bd9a6;hb=f0100ff3f6adb41d257ab5bff5fef390a8f458e2;hp=6fa618eb1af85c7bd23f0dc6c4d07eb3cdb026b0;hpb=eccf22528f8b4c21cdbd2f620cbe39dbb38ea6e1;p=oota-llvm.git diff --git a/include/llvm/Support/MathExtras.h b/include/llvm/Support/MathExtras.h index 6fa618eb1af..9c5f32cd5ff 100644 --- a/include/llvm/Support/MathExtras.h +++ b/include/llvm/Support/MathExtras.h @@ -14,7 +14,7 @@ #ifndef LLVM_SUPPORT_MATHEXTRAS_H #define LLVM_SUPPORT_MATHEXTRAS_H -#include "llvm/Support/DataTypes.h" +#include "llvm/System/DataTypes.h" namespace llvm { @@ -32,35 +32,43 @@ inline uint32_t Lo_32(uint64_t Value) { return static_cast(Value); } -/// is?Type - these functions produce optimal testing for integer data types. -inline bool isInt8 (int64_t Value) { - return static_cast(Value) == Value; -} -inline bool isUInt8 (int64_t Value) { - return static_cast(Value) == Value; -} -inline bool isInt16 (int64_t Value) { - return static_cast(Value) == Value; -} -inline bool isUInt16(int64_t Value) { - return static_cast(Value) == Value; -} -inline bool isInt32 (int64_t Value) { - return static_cast(Value) == Value; -} -inline bool isUInt32(int64_t Value) { - return static_cast(Value) == Value; -} - +/// isInt - Checks if an integer fits into the given bit width. template inline bool isInt(int64_t x) { return N >= 64 || (-(INT64_C(1)<<(N-1)) <= x && x < (INT64_C(1)<<(N-1))); } +// Template specializations to get better code for common cases. +template<> +inline bool isInt<8>(int64_t x) { + return static_cast(x) == x; +} +template<> +inline bool isInt<16>(int64_t x) { + return static_cast(x) == x; +} +template<> +inline bool isInt<32>(int64_t x) { + return static_cast(x) == x; +} +/// isUInt - Checks if an unsigned integer fits into the given bit width. template -inline bool isUint(uint64_t x) { +inline bool isUInt(uint64_t x) { return N >= 64 || x < (UINT64_C(1)< +inline bool isUInt<8>(uint64_t x) { + return static_cast(x) == x; +} +template<> +inline bool isUInt<16>(uint64_t x) { + return static_cast(x) == x; +} +template<> +inline bool isUInt<32>(uint64_t x) { + return static_cast(x) == x; +} /// isMask_32 - This function returns true if the argument is a sequence of ones /// starting at the least significant bit with the remainder zero (32 bit @@ -160,7 +168,7 @@ inline unsigned CountLeadingZeros_32(uint32_t Value) { #else if (!Value) return 32; Count = 0; - // bisecton method for count leading zeros + // bisection method for count leading zeros for (unsigned Shift = 32 >> 1; Shift; Shift >>= 1) { uint32_t Tmp = Value >> Shift; if (Tmp) { @@ -197,7 +205,7 @@ inline unsigned CountLeadingZeros_64(uint64_t Value) { if (sizeof(long) == sizeof(int64_t)) { if (!Value) return 64; Count = 0; - // bisecton method for count leading zeros + // bisection method for count leading zeros for (unsigned Shift = 64 >> 1; Shift; Shift >>= 1) { uint64_t Tmp = Value >> Shift; if (Tmp) {