aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Support/MathExtras.h
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2010-03-29 21:13:41 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2010-03-29 21:13:41 +0000
commit34247a0f356edf45ae3ad9ce04e1f90a77c6dba7 (patch)
treec39dfe906f22a3585017ec3fa9b9a34528dc5fff /include/llvm/Support/MathExtras.h
parent31441b7e95e0840e1ae144e5db6f791d6a36bc60 (diff)
Make isInt?? and isUint?? template specializations of the generic versions. This
makes calls a little bit more consistent and allows easy removal of the specializations in the future. Convert all callers to the templated functions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99838 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/MathExtras.h')
-rw-r--r--include/llvm/Support/MathExtras.h50
1 files changed, 29 insertions, 21 deletions
diff --git a/include/llvm/Support/MathExtras.h b/include/llvm/Support/MathExtras.h
index fa12416aea..9c5f32cd5f 100644
--- a/include/llvm/Support/MathExtras.h
+++ b/include/llvm/Support/MathExtras.h
@@ -32,35 +32,43 @@ inline uint32_t Lo_32(uint64_t Value) {
return static_cast<uint32_t>(Value);
}
-/// is?Type - these functions produce optimal testing for integer data types.
-inline bool isInt8 (int64_t Value) {
- return static_cast<int8_t>(Value) == Value;
-}
-inline bool isUInt8 (int64_t Value) {
- return static_cast<uint8_t>(Value) == Value;
-}
-inline bool isInt16 (int64_t Value) {
- return static_cast<int16_t>(Value) == Value;
-}
-inline bool isUInt16(int64_t Value) {
- return static_cast<uint16_t>(Value) == Value;
-}
-inline bool isInt32 (int64_t Value) {
- return static_cast<int32_t>(Value) == Value;
-}
-inline bool isUInt32(int64_t Value) {
- return static_cast<uint32_t>(Value) == Value;
-}
-
+/// isInt - Checks if an integer fits into the given bit width.
template<unsigned N>
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<int8_t>(x) == x;
+}
+template<>
+inline bool isInt<16>(int64_t x) {
+ return static_cast<int16_t>(x) == x;
+}
+template<>
+inline bool isInt<32>(int64_t x) {
+ return static_cast<int32_t>(x) == x;
+}
+/// isUInt - Checks if an unsigned integer fits into the given bit width.
template<unsigned N>
-inline bool isUint(uint64_t x) {
+inline bool isUInt(uint64_t x) {
return N >= 64 || x < (UINT64_C(1)<<N);
}
+// Template specializations to get better code for common cases.
+template<>
+inline bool isUInt<8>(uint64_t x) {
+ return static_cast<uint8_t>(x) == x;
+}
+template<>
+inline bool isUInt<16>(uint64_t x) {
+ return static_cast<uint16_t>(x) == x;
+}
+template<>
+inline bool isUInt<32>(uint64_t x) {
+ return static_cast<uint32_t>(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