From ed3d17e14c1edbbb114e1490bca5e998cd108e86 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Sun, 13 Jun 2010 16:07:49 +0200 Subject: u_math: Add align function npot alignments --- src/gallium/auxiliary/util/u_math.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/gallium/auxiliary/util/u_math.h') 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) { -- cgit v1.2.3