7#include "zen/config.hpp"
15constexpr bool is_power_of_2_32(uint32_t Value) {
16 return std::has_single_bit(Value);
20constexpr bool is_power_of_2_64(uint64_t Value) {
21 return std::has_single_bit(Value);
26inline unsigned log2_64(uint64_t Value) {
27 return 63 - std::countl_zero(Value);
32inline unsigned log2_64_ceil(uint64_t Value) {
33 return 64 - std::countl_zero(Value - 1);
38constexpr uint64_t next_power_of_2(uint64_t A) {
50inline uint64_t power_of_2_ceil(uint64_t A) {
51 if (!A || A > UINT64_MAX / 2)
53 return UINT64_C(1) << log2_64_ceil(A);
59template<std::
integral A, std::
unsigned_
integral B>
60inline A ipow(A x, B p) {
63 int tmp = ipow(x, p / 2);
64 if (p % 2 == 0)
return tmp * tmp;
65 else return x * tmp * tmp;