util: move ALIGN/ROUND_DOWN_TO to u_math.h

These are less mesa specific than the rest of macros.h, and would be
nice to use outside of mesa.  Prep for next patch.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4381>
This commit is contained in:
Rob Clark 2020-03-30 15:52:30 -07:00 committed by Marge Bot
parent 7a53e67816
commit ae7da1a017
2 changed files with 46 additions and 46 deletions

View file

@ -691,52 +691,6 @@ minify(unsigned value, unsigned levels)
return MAX2(1, value >> levels);
}
/**
* Align a value up to an alignment value
*
* If \c value is not already aligned to the requested alignment value, it
* will be rounded up.
*
* \param value Value to be rounded
* \param alignment Alignment value to be used. This must be a power of two.
*
* \sa ROUND_DOWN_TO()
*/
static inline uintptr_t
ALIGN(uintptr_t value, int32_t alignment)
{
assert((alignment > 0) && _mesa_is_pow_two(alignment));
return (((value) + (alignment) - 1) & ~((alignment) - 1));
}
/**
* Like ALIGN(), but works with a non-power-of-two alignment.
*/
static inline uintptr_t
ALIGN_NPOT(uintptr_t value, int32_t alignment)
{
assert(alignment > 0);
return (value + alignment - 1) / alignment * alignment;
}
/**
* Align a value down to an alignment value
*
* If \c value is not already aligned to the requested alignment value, it
* will be rounded down.
*
* \param value Value to be rounded
* \param alignment Alignment value to be used. This must be a power of two.
*
* \sa ALIGN()
*/
static inline uintptr_t
ROUND_DOWN_TO(uintptr_t value, int32_t alignment)
{
assert((alignment > 0) && _mesa_is_pow_two(alignment));
return ((value) & ~(alignment - 1));
}
/** Cross product of two 3-element vectors */
static inline void

View file

@ -659,6 +659,52 @@ util_memcpy_cpu_to_le32(void * restrict dest, const void * restrict src, size_t
#define MAX4( A, B, C, D ) ((A) > (B) ? MAX3(A, C, D) : MAX3(B, C, D))
/**
* Align a value up to an alignment value
*
* If \c value is not already aligned to the requested alignment value, it
* will be rounded up.
*
* \param value Value to be rounded
* \param alignment Alignment value to be used. This must be a power of two.
*
* \sa ROUND_DOWN_TO()
*/
static inline uintptr_t
ALIGN(uintptr_t value, int32_t alignment)
{
assert(util_is_power_of_two_nonzero(alignment));
return (((value) + (alignment) - 1) & ~((alignment) - 1));
}
/**
* Like ALIGN(), but works with a non-power-of-two alignment.
*/
static inline uintptr_t
ALIGN_NPOT(uintptr_t value, int32_t alignment)
{
assert(alignment > 0);
return (value + alignment - 1) / alignment * alignment;
}
/**
* Align a value down to an alignment value
*
* If \c value is not already aligned to the requested alignment value, it
* will be rounded down.
*
* \param value Value to be rounded
* \param alignment Alignment value to be used. This must be a power of two.
*
* \sa ALIGN()
*/
static inline uintptr_t
ROUND_DOWN_TO(uintptr_t value, int32_t alignment)
{
assert(util_is_power_of_two_nonzero(alignment));
return ((value) & ~(alignment - 1));
}
/**
* Align a value, only works pot alignemnts.
*/