Mesa (master): llvmpipe: Unbreak rasterization on 64bit.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Mon Sep 13 11:04:16 UTC 2010


Module: Mesa
Branch: master
Commit: 501d43028e8e551dd36ede00fb85095183c32037
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=501d43028e8e551dd36ede00fb85095183c32037

Author: José Fonseca <jfonseca at vmware.com>
Date:   Mon Sep 13 12:03:07 2010 +0100

llvmpipe: Unbreak rasterization on 64bit.

---

 src/gallium/drivers/llvmpipe/lp_setup_tri.c |   46 +++++++++++++--------------
 1 files changed, 22 insertions(+), 24 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_setup_tri.c b/src/gallium/drivers/llvmpipe/lp_setup_tri.c
index f0c74f8..3b7fd5d 100644
--- a/src/gallium/drivers/llvmpipe/lp_setup_tri.c
+++ b/src/gallium/drivers/llvmpipe/lp_setup_tri.c
@@ -440,30 +440,28 @@ do_triangle_ccw(struct lp_setup_context *setup,
 }
 
 /*
- * __fls: find last set bit in word
- * @word: The word to search
+ * Round to nearest less or equal power of two of the input.
  *
- * Undefined if no zero exists, so code should check against ~0UL first.
+ * Undefined if no bit set exists, so code should check against 0 first.
  */
-#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86)
-static inline unsigned fls(unsigned word)
+static INLINE uint32_t 
+floor_pot(uint32_t n)
 {
-        asm("bsr %1,%0"
-            : "=r" (word)
-            : "rm" (word));
-        return word;
-}
+   assert(n);
+#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86)
+   asm("bsr %1,%0"
+       : "=r" (n)
+       : "rm" (n));
+   return 1 << n;
 #else
-static inline unsigned fls(unsigned n)
-{
-    n |= (n >>  1);
-    n |= (n >>  2);
-    n |= (n >>  4);
-    n |= (n >>  8);
-    n |= (n >> 16);
-    return n - (n >> 1);
-}
+   n |= (n >>  1);
+   n |= (n >>  2);
+   n |= (n >>  4);
+   n |= (n >>  8);
+   n |= (n >> 16);
+   return n - (n >> 1);
 #endif
+}
 
 
 boolean
@@ -477,14 +475,14 @@ lp_setup_bin_triangle( struct lp_setup_context *setup,
 
    /* What is the largest power-of-two boundary this triangle crosses:
     */
-   int dx = 1 << fls((bbox->x0 ^ bbox->x1) |
-		     (bbox->y0 ^ bbox->y1));
+   int dx = floor_pot((bbox->x0 ^ bbox->x1) |
+		      (bbox->y0 ^ bbox->y1));
 
    /* The largest dimension of the rasterized area of the triangle
-    * (aligned to a 4x4 grid), rounded up to the next power of two:
+    * (aligned to a 4x4 grid), rounded down to the nearest power of two:
     */
-   int sz = 1 << fls((bbox->x1 - (bbox->x0 & ~3)) |
-		     (bbox->y1 - (bbox->y0 & ~3)));
+   int sz = floor_pot((bbox->x1 - (bbox->x0 & ~3)) |
+		      (bbox->y1 - (bbox->y0 & ~3)));
 
    if (nr_planes == 3) {
       if (sz < 4 && dx < 64)




More information about the mesa-commit mailing list