From: Ian Romanick <ian.d.roman...@intel.com>

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.

Cc: Eric Anholt <e...@anholt.net>
Cc: Chris Wilson <ch...@chris-wilson.co.uk>
---
 src/mesa/drivers/dri/intel/intel_context.h |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/mesa/drivers/dri/intel/intel_context.h 
b/src/mesa/drivers/dri/intel/intel_context.h
index 772b2fb..8de4a89 100644
--- a/src/mesa/drivers/dri/intel/intel_context.h
+++ b/src/mesa/drivers/dri/intel/intel_context.h
@@ -295,9 +295,8 @@ 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))
+#define ALIGN(value, alignment)  (((value) + alignment - 1) & ~(alignment - 1))
+#define ROUND_DOWN_TO(value, alignment) ((value) & ~(alignment - 1))
 #define IS_POWER_OF_TWO(val) (((val) & (val - 1)) == 0)
 
 static INLINE uint32_t
-- 
1.7.4

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

Reply via email to