diff options
Diffstat (limited to 'include/llvm/Support/MathExtras.h')
-rw-r--r-- | include/llvm/Support/MathExtras.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/include/llvm/Support/MathExtras.h b/include/llvm/Support/MathExtras.h index 4627557..d085c94 100644 --- a/include/llvm/Support/MathExtras.h +++ b/include/llvm/Support/MathExtras.h @@ -51,6 +51,13 @@ inline bool isInt<32>(int64_t x) { return static_cast<int32_t>(x) == x; } +/// isShiftedInt<N,S> - Checks if a signed integer is an N bit number shifted +/// left by S. +template<unsigned N, unsigned S> +inline bool isShiftedInt(int64_t x) { + return isInt<N+S>(x) && (x % (1<<S) == 0); +} + /// isUInt - Checks if an unsigned integer fits into the given bit width. template<unsigned N> inline bool isUInt(uint64_t x) { @@ -70,6 +77,13 @@ inline bool isUInt<32>(uint64_t x) { return static_cast<uint32_t>(x) == x; } +/// isShiftedUInt<N,S> - Checks if a unsigned integer is an N bit number shifted +/// left by S. +template<unsigned N, unsigned S> +inline bool isShiftedUInt(uint64_t x) { + return isUInt<N+S>(x) && (x % (1<<S) == 0); +} + /// isUIntN - Checks if an unsigned integer fits into the given (dynamic) /// bit width. inline bool isUIntN(unsigned N, uint64_t x) { |