On 06/01/2015 11:13 AM, Nanley Chery wrote:
From: Nanley Chery <nanley.g.ch...@intel.com>

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.

Signed-off-by: Nanley Chery <nanley.g.ch...@intel.com>
---
  src/mesa/main/macros.h | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/macros.h b/src/mesa/main/macros.h
index c794da3..1348b08 100644
--- a/src/mesa/main/macros.h
+++ b/src/mesa/main/macros.h
@@ -700,7 +700,10 @@ is_power_of_two(unsigned value)
   *
   * \sa ROUND_DOWN_TO()
   */
-#define ALIGN(value, alignment)  (((value) + (alignment) - 1) & ~((alignment) 
- 1))
+#define ALIGN(value, alignment) ({                        \
+      assert(is_power_of_two(alignment));                 \
+      (((value) + (alignment) - 1) & ~((alignment) - 1)); \
+   })


That construct will not compile with MSVC unfortunately (I just tested it).

-Brian

  /**
   * Align a value down to an alignment value
@@ -713,7 +716,10 @@ is_power_of_two(unsigned value)
   *
   * \sa ALIGN()
   */
-#define ROUND_DOWN_TO(value, alignment) ((value) & ~(alignment - 1))
+#define ROUND_DOWN_TO(value, alignment) ({                \
+      assert(is_power_of_two(alignment));                 \
+      ((value) & ~(alignment - 1));                       \
+   })

  /**
   * Align a value up to an alignment value


_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to