2025-01-30 21:33:00 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-12-18 09:57:16 -05:00
|
|
|
#include <climits>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
2025-01-30 21:33:00 -05:00
|
|
|
inline constexpr uint32_t next_pow_2(uint32_t const num) {
|
2024-12-18 09:57:16 -05:00
|
|
|
if (num <= 1) return num;
|
|
|
|
|
return 1 << (CHAR_BIT * sizeof(num) - __builtin_clz(num - 1));
|
2025-01-30 21:33:00 -05:00
|
|
|
}
|
2025-05-01 07:59:28 -07:00
|
|
|
|
|
|
|
|
template <typename A, typename B>
|
|
|
|
|
static inline constexpr auto div_ceil(A a, B b) {
|
|
|
|
|
return (a + b - 1) / b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Round a down to the next multiple of b. The caller is responsible for making
|
|
|
|
|
// sure that b is non-zero
|
|
|
|
|
template <typename T>
|
|
|
|
|
inline constexpr T round_to_previous_multiple_of(T a, T b) {
|
|
|
|
|
return a % b == 0 ? a : (a / b) * b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Round a up to the next multiple of b. The caller is responsible for making
|
|
|
|
|
// sure that b is non-zero
|
|
|
|
|
template <typename T>
|
|
|
|
|
inline constexpr T round_to_next_multiple_of(T a, T b) {
|
|
|
|
|
return a % b == 0 ? a : ((a / b) + 1) * b;
|
|
|
|
|
}
|