Mesa (gallium-integer-opcodes): tgsi/ureg: Improve immediate match & expand logic.

Michał Król michal at kemper.freedesktop.org
Wed Dec 23 10:24:30 PST 2009


Module: Mesa
Branch: gallium-integer-opcodes
Commit: bc36ee61a25736843eb15f5dce9799ebc09c83f1
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=bc36ee61a25736843eb15f5dce9799ebc09c83f1

Author: Michal Krol <michal at vmware.com>
Date:   Wed Dec 23 19:08:45 2009 +0100

tgsi/ureg: Improve immediate match & expand logic.

Do not pollute immediates with unsuccessfull attempts to expand them.

---

 src/gallium/auxiliary/tgsi/tgsi_ureg.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
index 96e9bb9..7afd986 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_ureg.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
@@ -495,9 +495,10 @@ static int
 match_or_expand_immediate( const unsigned *v,
                            unsigned nr,
                            unsigned *v2,
-                           unsigned *nr2,
+                           unsigned *pnr2,
                            unsigned *swizzle )
 {
+   unsigned nr2 = *pnr2;
    unsigned i, j;
 
    *swizzle = 0;
@@ -505,7 +506,7 @@ match_or_expand_immediate( const unsigned *v,
    for (i = 0; i < nr; i++) {
       boolean found = FALSE;
 
-      for (j = 0; j < *nr2 && !found; j++) {
+      for (j = 0; j < nr2 && !found; j++) {
          if (v[i] == v2[j]) {
             *swizzle |= j << (i * 2);
             found = TRUE;
@@ -513,16 +514,19 @@ match_or_expand_immediate( const unsigned *v,
       }
 
       if (!found) {
-         if (*nr2 >= 4) {
+         if (nr2 >= 4) {
             return FALSE;
          }
 
-         v2[*nr2] = v[i];
-         *swizzle |= *nr2 << (i * 2);
-         (*nr2)++;
+         v2[nr2] = v[i];
+         *swizzle |= nr2 << (i * 2);
+         nr2++;
       }
    }
 
+   /* Actually expand immediate only when fully succeeded.
+    */
+   *pnr2 = nr2;
    return TRUE;
 }
 



More information about the mesa-commit mailing list