Files
FEX-Emu--FEX/FEXCore/include/FEXCore/Utils/MathUtils.h
T
Alyssa Rosenzweig af21b8f3c7 Move External/FEXCore/ to FEXCore/
It is not an external component, and it makes paths needlessly long.
Ryan seemed amenable to this when we discussed on IRC earlier.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
2023-08-17 16:32:16 -04:00

28 lines
725 B
C++

#pragma once
#include <FEXCore/Utils/LogManager.h>
#include <bit>
#include <cstdint>
#include <type_traits>
namespace FEXCore {
[[nodiscard]] constexpr uint64_t AlignUp(uint64_t value, uint64_t size) {
return value + (size - value % size) % size;
}
[[nodiscard]] constexpr uint64_t AlignDown(uint64_t value, uint64_t size) {
return value - value % size;
}
// Returns the ilog2 of a power-of-2 integer.
// Asserts in the case that the passed in integer is not a power-of-2.
template<typename T>
requires(std::is_unsigned_v<T>)
[[nodiscard]] constexpr T ilog2(T Value) {
LOGMAN_THROW_A_FMT(std::has_single_bit(Value), "ilog2 requires popcount to be one");
return std::countr_zero(Value);
}
} // namespace FEXCore