Mesa (7.10): intel: Fix ROUND_DOWN_TO macro

Ian Romanick idr at kemper.freedesktop.org
Thu Apr 21 10:38:26 PDT 2011


Module: Mesa
Branch: 7.10
Commit: ff77a69ae33f04b2fbfdc9a228214ef373d54f61
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ff77a69ae33f04b2fbfdc9a228214ef373d54f61

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Fri Apr  8 16:31:22 2011 -0700

intel: Fix ROUND_DOWN_TO macro

Previously the macro would (ALIGN(value - alignment - 1, alignment)).
At the very least, this was missing parenthesis around "alignment -
1".  As a result, if value was already aligned, it would be reduced by
alignment.  Condisder:

     x = ROUND_DOWN_TO(256, 128);

This becomes:

    x = ALIGN(256 - 128 - 1, 128);

Or:

    x = ALIGN(127, 128);

Which becomes:

    x = 128;

This macro is currently only used in brw_state_batch
(brw_state_batch.c).  It looks like the original version of this macro
would just use too much space in the batch buffer.  It's possible, but
not at all clear to me from the code, that the original behavior is
actually desired.

In any case, this patch does not cause any piglit regressions on my
Ironlake system.

I also think that ALIGN_FLOOR would be a better name for this macro,
but ROUND_DOWN_TO matches rounddown in the Linux kernel.

Reviewed-by: Eric Anholt <eric at anholt.net>
Reviewed-by: Keith Whitwell <keithw at vmware.com>
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
(cherry picked from commit 7e809f0b8d635c8d5519b3d0fdaf11ac0ddda7eb)

---

 src/mesa/drivers/dri/intel/intel_context.h |   30 +++++++++++++++++++++++++--
 1 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/mesa/drivers/dri/intel/intel_context.h b/src/mesa/drivers/dri/intel/intel_context.h
index 53a11ba..f3e856d 100644
--- a/src/mesa/drivers/dri/intel/intel_context.h
+++ b/src/mesa/drivers/dri/intel/intel_context.h
@@ -278,9 +278,33 @@ extern char *__progname;
 #define SUBPIXEL_Y 0.125
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
-#define ALIGN(value, alignment)  ((value + alignment - 1) & ~(alignment - 1))
-#define ROUND_DOWN_TO(value, alignment) (ALIGN(value - alignment - 1, \
-					       alignment))
+
+/**
+ * Align a value up to an alignment value
+ *
+ * If \c value is not already aligned to the requested alignment value, it
+ * will be rounded up.
+ *
+ * \param value  Value to be rounded
+ * \param alignment  Alignment value to be used.  This must be a power of two.
+ *
+ * \sa ROUND_DOWN_TO()
+ */
+#define ALIGN(value, alignment)  (((value) + alignment - 1) & ~(alignment - 1))
+
+/**
+ * Align a value down to an alignment value
+ *
+ * If \c value is not already aligned to the requested alignment value, it
+ * will be rounded down.
+ *
+ * \param value  Value to be rounded
+ * \param alignment  Alignment value to be used.  This must be a power of two.
+ *
+ * \sa ALIGN()
+ */
+#define ROUND_DOWN_TO(value, alignment) ((value) & ~(alignment - 1))
+
 #define IS_POWER_OF_TWO(val) (((val) & (val - 1)) == 0)
 
 static INLINE uint32_t



More information about the mesa-commit mailing list