From: Jakob Bornecrantz Date: Sun, 13 Jun 2010 14:07:49 +0000 (+0200) Subject: u_math: Add align function npot alignments X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ed3d17e14c1edbbb114e1490bca5e998cd108e86;p=mesa.git u_math: Add align function npot alignments --- diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h index 6370e779865..fe19466436a 100644 --- a/src/gallium/auxiliary/util/u_math.h +++ b/src/gallium/auxiliary/util/u_math.h @@ -567,12 +567,26 @@ util_bswap16(uint16_t n) #define MAX3( A, B, C ) MAX2( MAX2( A, B ), C ) +/** + * Align a value, only works pot alignemnts. + */ static INLINE int align(int value, int alignment) { return (value + alignment - 1) & ~(alignment - 1); } +/** + * Works like align but on npot alignments. + */ +static INLINE size_t +util_align_npot(size_t value, size_t alignment) +{ + if (value % alignment) + return value + (alignment - (value % alignment)); + return value; +} + static INLINE unsigned u_minify(unsigned value, unsigned levels) {