Fix logic in _slang_simplify(): vec2() constructor case wasn't getting used.
authorBrian <brian@yutani.localnet.net>
Fri, 2 Feb 2007 01:11:19 +0000 (18:11 -0700)
committerBrian <brian@yutani.localnet.net>
Fri, 2 Feb 2007 01:11:19 +0000 (18:11 -0700)
src/mesa/shader/slang/slang_codegen.c
src/mesa/shader/slang/slang_simplify.c
src/mesa/shader/slang/slang_simplify.h

index d09883c66456d6e320805185f226934003e32abb..ee1d6cbabc0445b570df201ed9643d2dcc48ddaa 100644 (file)
@@ -1891,6 +1891,9 @@ _slang_gen_declaration(slang_assemble_ctx *A, slang_operation *oper)
          RETURN_ERROR2("Undefined variable:", varName, 0);
       }
       /* XXX make copy of this initializer? */
+
+      /* XXX try to simplify initializer here */foo
+
       rhs = _slang_gen_operation(A, v->initializer);
       assert(rhs);
       init = new_node(IR_MOVE, var, rhs);
@@ -2649,7 +2652,7 @@ _slang_codegen_global_variable(slang_assemble_ctx *A, slang_variable *var,
          lhs->Store = n->Store;
 
          /* constant folding, etc */
-         slang_simplify(var->initializer, &A->space, A->atoms);
+         _slang_simplify(var->initializer, &A->space, A->atoms);
 
          rhs = _slang_gen_operation(A, var->initializer);
          assert(rhs);
@@ -2703,7 +2706,7 @@ _slang_codegen_function(slang_assemble_ctx * A, slang_function * fun)
    assert(A->vartable);
 
    /* fold constant expressions, etc. */
-   slang_simplify(fun->body, &A->space, A->atoms);
+   _slang_simplify(fun->body, &A->space, A->atoms);
 
    A->CurFunction = fun;
 
index 821a716f58c5fd4514165903535304dd3f3c2438..c71313a7bb84effab4b11af241918062b569eacd 100644 (file)
@@ -44,9 +44,9 @@
  * declarations.  I.e.:  float foo[3 + 5];
  */
 void
-slang_simplify(slang_operation *oper,
-               const slang_assembly_name_space * space,
-               slang_atom_pool * atoms)
+_slang_simplify(slang_operation *oper,
+                const slang_assembly_name_space * space,
+                slang_atom_pool * atoms)
 {
    GLboolean isFloat[4];
    GLboolean isBool[4];
@@ -54,7 +54,7 @@ slang_simplify(slang_operation *oper,
 
    /* first, simplify children */
    for (i = 0; i < oper->num_children; i++) {
-      slang_simplify(&oper->children[i], space, atoms);
+      _slang_simplify(&oper->children[i], space, atoms);
    }
 
    /* examine children */
@@ -75,7 +75,7 @@ slang_simplify(slang_operation *oper,
          }
          slang_operation_destruct(oper);
          oper->type = slang_oper_literal_float;
-         break;
+         return;
       case slang_oper_subtract:
          for (i = 0; i < 4; i++) {
             oper->literal[i]
@@ -83,7 +83,7 @@ slang_simplify(slang_operation *oper,
          }
          slang_operation_destruct(oper);
          oper->type = slang_oper_literal_float;
-         break;
+         return;
       case slang_oper_multiply:
          for (i = 0; i < 4; i++) {
             oper->literal[i]
@@ -91,7 +91,7 @@ slang_simplify(slang_operation *oper,
          }
          slang_operation_destruct(oper);
          oper->type = slang_oper_literal_float;
-         break;
+         return;
       case slang_oper_divide:
          for (i = 0; i < 4; i++) {
             oper->literal[i]
@@ -99,12 +99,13 @@ slang_simplify(slang_operation *oper,
          }
          slang_operation_destruct(oper);
          oper->type = slang_oper_literal_float;
-         break;
+         return;
       default:
          ; /* nothing */
       }
    }
-   else if (n == 1 && isFloat[0]) {
+
+   if (n == 1 && isFloat[0]) {
       switch (oper->type) {
       case slang_oper_minus:
          for (i = 0; i < 4; i++) {
@@ -112,17 +113,18 @@ slang_simplify(slang_operation *oper,
          }
          slang_operation_destruct(oper);
          oper->type = slang_oper_literal_float;
-         break;
+         return;
       case slang_oper_plus:
          COPY_4V(oper->literal, oper->children[0].literal);
          slang_operation_destruct(oper);
          oper->type = slang_oper_literal_float;
-         break;
+         return;
       default:
          ; /* nothing */
       }
    }
-   else if (n == 2 && isBool[0] && isBool[1]) {
+
+   if (n == 2 && isBool[0] && isBool[1]) {
       /* simple boolean expression */
       switch (oper->type) {
       case slang_oper_logicaland:
@@ -133,7 +135,7 @@ slang_simplify(slang_operation *oper,
          }
          slang_operation_destruct(oper);
          oper->type = slang_oper_literal_bool;
-         break;
+         return;
       case slang_oper_logicalor:
          for (i = 0; i < 4; i++) {
             const GLint a = oper->children[0].literal[i] ? 1 : 0;
@@ -142,7 +144,7 @@ slang_simplify(slang_operation *oper,
          }
          slang_operation_destruct(oper);
          oper->type = slang_oper_literal_bool;
-         break;
+         return;
       case slang_oper_logicalxor:
          for (i = 0; i < 4; i++) {
             const GLint a = oper->children[0].literal[i] ? 1 : 0;
@@ -151,12 +153,13 @@ slang_simplify(slang_operation *oper,
          }
          slang_operation_destruct(oper);
          oper->type = slang_oper_literal_bool;
-         break;
+         return;
       default:
          ; /* nothing */
       }
    }
-   else if (n == 4 && isFloat[0] && isFloat[1] && isFloat[2] && isFloat[3]) {
+
+   if (n == 4 && isFloat[0] && isFloat[1] && isFloat[2] && isFloat[3]) {
       /* vec4(flt, flt, flt, flt) constructor */
       if (oper->type == slang_oper_call) {
          if (strcmp((char *) oper->a_id, "vec4") == 0) {
@@ -166,19 +169,37 @@ slang_simplify(slang_operation *oper,
             oper->literal[3] = oper->children[3].literal[0];
             slang_operation_destruct(oper);
             oper->type = slang_oper_literal_float;
+            return;
          }
       }
    }
-   else if (n == 3 && isFloat[0] && isFloat[1] && isFloat[2]) {
+
+   if (n == 3 && isFloat[0] && isFloat[1] && isFloat[2]) {
       /* vec3(flt, flt, flt) constructor */
       if (oper->type == slang_oper_call) {
          if (strcmp((char *) oper->a_id, "vec3") == 0) {
             oper->literal[0] = oper->children[0].literal[0];
             oper->literal[1] = oper->children[1].literal[0];
             oper->literal[2] = oper->children[2].literal[0];
-            oper->literal[3] = 0.0;
+            oper->literal[3] = oper->literal[2];
             slang_operation_destruct(oper);
             oper->type = slang_oper_literal_float;
+            return;
+         }
+      }
+   }
+
+   if (n == 2 && isFloat[0] && isFloat[1]) {
+      /* vec4(flt, flt) constructor */
+      if (oper->type == slang_oper_call) {
+         if (strcmp((char *) oper->a_id, "vec2") == 0) {
+            oper->literal[0] = oper->children[0].literal[0];
+            oper->literal[1] = oper->children[1].literal[0];
+            oper->literal[2] = oper->literal[1];
+            oper->literal[3] = oper->literal[1];
+            slang_operation_destruct(oper); /* XXX oper->locals goes NULL! */
+            oper->type = slang_oper_literal_float;
+            return;
          }
       }
    }
index 0ca1fa2f0d24cf75a6f9ea55092b3bbed1c90ea5..5ff7292f0fb6a2bb47a612ee207aaaed9aec52a8 100644 (file)
@@ -3,9 +3,9 @@
 #define SLANG_SIMPLIFY_H
 
 extern void
-slang_simplify(slang_operation *oper,
-               const slang_assembly_name_space * space,
-               slang_atom_pool * atoms);
+_slang_simplify(slang_operation *oper,
+                const slang_assembly_name_space * space,
+                slang_atom_pool * atoms);
 
 
 extern GLboolean