summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/macros.h
diff options
context:
space:
mode:
authorNanley Chery <nanley.g.chery@intel.com>2015-05-27 13:25:30 -0700
committerNanley Chery <nanley.g.chery@intel.com>2015-08-26 14:36:43 -0700
commit97f4efd573aed7ffc0ea9395f4e69ccdeb5041f6 (patch)
tree0aba606a6f9f482fa49a544f797913d3a5ce2d68 /src/mesa/main/macros.h
parent8b1f008e9acf94645a28c27fa261f6450a3edb84 (diff)
downloadexternal_mesa3d-97f4efd573aed7ffc0ea9395f4e69ccdeb5041f6.zip
external_mesa3d-97f4efd573aed7ffc0ea9395f4e69ccdeb5041f6.tar.gz
external_mesa3d-97f4efd573aed7ffc0ea9395f4e69ccdeb5041f6.tar.bz2
mesa/macros: add power-of-two assertions for alignment macros
ALIGN and ROUND_DOWN_TO both require that the alignment value passed into the macro be a power of two in the comments. Using software assertions verifies this to be the case. v2: use static inline functions instead of gcc-specific statement expressions (Brian). v3: fix indendation (Brian). v4: add greater than zero requirement (Anuj). Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com> Signed-off-by: Nanley Chery <nanley.g.chery@intel.com>
Diffstat (limited to 'src/mesa/main/macros.h')
-rw-r--r--src/mesa/main/macros.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/mesa/main/macros.h b/src/mesa/main/macros.h
index 54df50c..c3ef42a 100644
--- a/src/mesa/main/macros.h
+++ b/src/mesa/main/macros.h
@@ -690,7 +690,12 @@ minify(unsigned value, unsigned levels)
*
* \sa ROUND_DOWN_TO()
*/
-#define ALIGN(value, alignment) (((value) + (alignment) - 1) & ~((alignment) - 1))
+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));
+}
/**
* Align a value down to an alignment value
@@ -703,7 +708,12 @@ minify(unsigned value, unsigned levels)
*
* \sa ALIGN()
*/
-#define ROUND_DOWN_TO(value, alignment) ((value) & ~(alignment - 1))
+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 */