#pragma once

#include <cstdint>

namespace kuiper
{

// https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2

inline std::uint64_t next_pow2(std::uint64_t value) {
    value--;
    value |= value >> 1;
    value |= value >> 2;
    value |= value >> 4;
    value |= value >> 8;
    value |= value >> 16;
    value |= value >> 32;
    value++;
    value += (value == 0); // Case for if value == 0 (returns 0 as the next power of 2, which 0 is not)

    return value;
}

inline std::uint32_t next_pow2(std::uint32_t value) {
    value--;
    value |= value >> 1;
    value |= value >> 2;
    value |= value >> 4;
    value |= value >> 8;
    value |= value >> 16;
    value++;
    value += (value == 0);

    return value;
}

} // namespace kuiper
