diff options
Diffstat (limited to 'runtime/utils.h')
-rw-r--r-- | runtime/utils.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/runtime/utils.h b/runtime/utils.h index 448c591f2b..b47de81d62 100644 --- a/runtime/utils.h +++ b/runtime/utils.h @@ -167,6 +167,10 @@ struct TypeIdentity { // For rounding integers. template<typename T> +static constexpr T RoundDown(T x, typename TypeIdentity<T>::type n) + __attribute__((warn_unused_result)); + +template<typename T> static constexpr T RoundDown(T x, typename TypeIdentity<T>::type n) { return DCHECK_CONSTEXPR(IsPowerOfTwo(n), , T(0)) @@ -174,17 +178,27 @@ static constexpr T RoundDown(T x, typename TypeIdentity<T>::type n) { } template<typename T> +static constexpr T RoundUp(T x, typename TypeIdentity<T>::type n) + __attribute__((warn_unused_result)); + +template<typename T> static constexpr T RoundUp(T x, typename TypeIdentity<T>::type n) { return RoundDown(x + n - 1, n); } // For aligning pointers. template<typename T> +static inline T* AlignDown(T* x, uintptr_t n) __attribute__((warn_unused_result)); + +template<typename T> static inline T* AlignDown(T* x, uintptr_t n) { return reinterpret_cast<T*>(RoundDown(reinterpret_cast<uintptr_t>(x), n)); } template<typename T> +static inline T* AlignUp(T* x, uintptr_t n) __attribute__((warn_unused_result)); + +template<typename T> static inline T* AlignUp(T* x, uintptr_t n) { return reinterpret_cast<T*>(RoundUp(reinterpret_cast<uintptr_t>(x), n)); } |