<div dir="ltr">These two patches provide a slightly different approach to what Tim did.  I think Tim's is fine but I also like the idea of conditions working based on SSA def, type, and read mask so I consider this a unification/cleanup rather than a counter-proposal.  Thoughts?<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 11, 2017 at 11:13 AM, Jason Ekstrand <span dir="ltr"><<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Instead of passing all of the ALU op information, we just pass what you<br>
need: The SSA def, the type it's being read as, and a component mask.<br>
---<br>
 src/compiler/nir/nir_search.c         | 12 +++++--<br>
 src/compiler/nir/nir_search.h         |  3 +-<br>
 src/compiler/nir/nir_search_<wbr>helpers.h | 62 +++++++++++++++++++-----------<wbr>-----<br>
 3 files changed, 44 insertions(+), 33 deletions(-)<br>
<br>
diff --git a/src/compiler/nir/nir_search.<wbr>c b/src/compiler/nir/nir_search.<wbr>c<br>
index 10a0941..2f57821 100644<br>
--- a/src/compiler/nir/nir_search.<wbr>c<br>
+++ b/src/compiler/nir/nir_search.<wbr>c<br>
@@ -154,8 +154,16 @@ match_value(const nir_search_value *value, nir_alu_instr *instr, unsigned src,<br>
              instr->src[src].src.ssa-><wbr>parent_instr->type != nir_instr_type_load_const)<br>
             return false;<br>
<br>
-         if (var->cond && !var->cond(instr, src, num_components, new_swizzle))<br>
-            return false;<br>
+         if (var->cond) {<br>
+            uint8_t read_mask = 0;<br>
+            for (unsigned i = 0; i < num_components; i++)<br>
+               read_mask |= 1 << new_swizzle[i];<br>
+<br>
+            if (!var->cond(instr->src[src].<wbr>src.ssa,<br>
+                           nir_op_infos[instr->op].input_<wbr>types[src],<br>
+                           read_mask))<br>
+               return false;<br>
+         }<br>
<br>
          if (var->type != nir_type_invalid &&<br>
              !src_is_type(instr->src[src].<wbr>src, var->type))<br>
diff --git a/src/compiler/nir/nir_search.<wbr>h b/src/compiler/nir/nir_search.<wbr>h<br>
index dec19d5..9d25018 100644<br>
--- a/src/compiler/nir/nir_search.<wbr>h<br>
+++ b/src/compiler/nir/nir_search.<wbr>h<br>
@@ -76,8 +76,7 @@ typedef struct {<br>
     * variables to require, for example, power-of-two in order for the search<br>
     * to match.<br>
     */<br>
-   bool (*cond)(nir_alu_instr *instr, unsigned src,<br>
-                unsigned num_components, const uint8_t *swizzle);<br>
+   bool (*cond)(nir_ssa_def *def, nir_alu_type type, uint8_t read_mask);<br>
 } nir_search_variable;<br>
<br>
 typedef struct {<br>
diff --git a/src/compiler/nir/nir_search_<wbr>helpers.h b/src/compiler/nir/nir_search_<wbr>helpers.h<br>
index 20fdae6..85f6c85 100644<br>
--- a/src/compiler/nir/nir_search_<wbr>helpers.h<br>
+++ b/src/compiler/nir/nir_search_<wbr>helpers.h<br>
@@ -36,25 +36,26 @@ __is_power_of_two(unsigned int x)<br>
 }<br>
<br>
 static inline bool<br>
-is_pos_power_of_two(nir_alu_<wbr>instr *instr, unsigned src, unsigned num_components,<br>
-                    const uint8_t *swizzle)<br>
+is_pos_power_of_two(nir_ssa_<wbr>def *def, nir_alu_type type, uint8_t read_mask)<br>
 {<br>
-   nir_const_value *val = nir_src_as_const_value(instr-><wbr>src[src].src);<br>
-<br>
-   /* only constant src's: */<br>
-   if (!val)<br>
+   if (def->parent_instr->type != nir_instr_type_load_const)<br>
       return false;<br>
<br>
-   for (unsigned i = 0; i < num_components; i++) {<br>
-      switch (nir_op_infos[instr->op].<wbr>input_types[src]) {<br>
+   nir_const_value *val = &nir_instr_as_load_const(def-><wbr>parent_instr)->value;<br>
+<br>
+   for (unsigned i = 0; i < 4; i++) {<br>
+      if (!(read_mask & (1 << i)))<br>
+         continue;<br>
+<br>
+      switch (type) {<br>
       case nir_type_int:<br>
-         if (val->i32[swizzle[i]] < 0)<br>
+         if (val->i32[i] < 0)<br>
             return false;<br>
-         if (!__is_power_of_two(val->i32[<wbr>swizzle[i]]))<br>
+         if (!__is_power_of_two(val->i32[<wbr>i]))<br>
             return false;<br>
          break;<br>
       case nir_type_uint:<br>
-         if (!__is_power_of_two(val->u32[<wbr>swizzle[i]]))<br>
+         if (!__is_power_of_two(val->u32[<wbr>i]))<br>
             return false;<br>
          break;<br>
       default:<br>
@@ -66,21 +67,22 @@ is_pos_power_of_two(nir_alu_<wbr>instr *instr, unsigned src, unsigned num_components,<br>
 }<br>
<br>
 static inline bool<br>
-is_neg_power_of_two(nir_alu_<wbr>instr *instr, unsigned src, unsigned num_components,<br>
-                    const uint8_t *swizzle)<br>
+is_neg_power_of_two(nir_ssa_<wbr>def *def, nir_alu_type type, uint8_t read_mask)<br>
 {<br>
-   nir_const_value *val = nir_src_as_const_value(instr-><wbr>src[src].src);<br>
-<br>
-   /* only constant src's: */<br>
-   if (!val)<br>
+   if (def->parent_instr->type != nir_instr_type_load_const)<br>
       return false;<br>
<br>
-   for (unsigned i = 0; i < num_components; i++) {<br>
-      switch (nir_op_infos[instr->op].<wbr>input_types[src]) {<br>
+   nir_const_value *val = &nir_instr_as_load_const(def-><wbr>parent_instr)->value;<br>
+<br>
+   for (unsigned i = 0; i < 4; i++) {<br>
+      if (!(read_mask & (1 << i)))<br>
+         continue;<br>
+<br>
+      switch (type) {<br>
       case nir_type_int:<br>
-         if (val->i32[swizzle[i]] > 0)<br>
+         if (val->i32[i] > 0)<br>
             return false;<br>
-         if (!__is_power_of_two(abs(val-><wbr>i32[swizzle[i]])))<br>
+         if (!__is_power_of_two(abs(val-><wbr>i32[i])))<br>
             return false;<br>
          break;<br>
       default:<br>
@@ -92,18 +94,20 @@ is_neg_power_of_two(nir_alu_<wbr>instr *instr, unsigned src, unsigned num_components,<br>
 }<br>
<br>
 static inline bool<br>
-is_zero_to_one(nir_alu_instr *instr, unsigned src, unsigned num_components,<br>
-               const uint8_t *swizzle)<br>
+is_zero_to_one(nir_ssa_def *def, nir_alu_type type, uint8_t read_mask)<br>
 {<br>
-   nir_const_value *val = nir_src_as_const_value(instr-><wbr>src[src].src);<br>
-<br>
-   if (!val)<br>
+   if (def->parent_instr->type != nir_instr_type_load_const)<br>
       return false;<br>
<br>
-   for (unsigned i = 0; i < num_components; i++) {<br>
-      switch (nir_op_infos[instr->op].<wbr>input_types[src]) {<br>
+   nir_const_value *val = &nir_instr_as_load_const(def-><wbr>parent_instr)->value;<br>
+<br>
+   for (unsigned i = 0; i < 4; i++) {<br>
+      if (!(read_mask & (1 << i)))<br>
+         continue;<br>
+<br>
+      switch (type) {<br>
       case nir_type_float:<br>
-         if (val->f32[swizzle[i]] < 0.0f || val->f32[swizzle[i]] > 1.0f)<br>
+         if (val->f32[i] < 0.0f || val->f32[i] > 1.0f)<br>
             return false;<br>
          break;<br>
       default:<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.5.0.400.gff86faf<br>
<br>
</font></span></blockquote></div><br></div>