mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-23 15:39:17 +01:00
Add NPOT AlignUp
utility
All our normal alignment functions are designed to only handle power of 2 (`POT`) multiples as we only align or check alignment to `POT` multiples but there are cases where this is not possible and we deal with `NPOT` multiples which is why this function is required.
This commit is contained in:
parent
662ea532d8
commit
7a0cfb484c
@ -70,7 +70,7 @@ namespace skyline::util {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The value aligned up to the next multiple
|
* @return The value aligned up to the next multiple
|
||||||
* @note The multiple needs to be a power of 2
|
* @note The multiple **must** be a power of 2
|
||||||
*/
|
*/
|
||||||
template<typename TypeVal>
|
template<typename TypeVal>
|
||||||
requires IsPointerOrUnsignedIntegral<TypeVal>
|
requires IsPointerOrUnsignedIntegral<TypeVal>
|
||||||
@ -79,9 +79,20 @@ namespace skyline::util {
|
|||||||
return ValuePointer<TypeVal>((PointerValue(value) + multiple) & ~(multiple));
|
return ValuePointer<TypeVal>((PointerValue(value) + multiple) & ~(multiple));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The value aligned up to the next multiple, the multiple is not restricted to being a power of two (NPOT)
|
||||||
|
* @note This will round away from zero for negative numbers
|
||||||
|
* @note This is costlier to compute than the power of 2 version, it should be preferred over this when possible
|
||||||
|
*/
|
||||||
|
template<typename TypeVal>
|
||||||
|
requires std::is_integral_v<TypeVal> || std::is_pointer_v<TypeVal>
|
||||||
|
constexpr TypeVal AlignUpNpot(TypeVal value, ssize_t multiple) {
|
||||||
|
return ValuePointer<TypeVal>(((PointerValue(value) + multiple - 1) / multiple) * multiple);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The value aligned down to the previous multiple
|
* @return The value aligned down to the previous multiple
|
||||||
* @note The multiple needs to be a power of 2
|
* @note The multiple **must** be a power of 2
|
||||||
*/
|
*/
|
||||||
template<typename TypeVal>
|
template<typename TypeVal>
|
||||||
requires IsPointerOrUnsignedIntegral<TypeVal>
|
requires IsPointerOrUnsignedIntegral<TypeVal>
|
||||||
|
Loading…
Reference in New Issue
Block a user