On 06/01/2015 11:46 AM, Brian Paul wrote:
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).

I also meant to suggest- perhaps you could convert the macro to an inline function.

-Brian

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

Reply via email to