[Mesa-dev] [PATCH 2/9] nir: stop passing swizzle to search condition

Timothy Arceri timothy.arceri at collabora.com
Tue Jan 10 09:41:51 UTC 2017


We can just get the swizzle from the instruction.
---
 src/compiler/nir/nir_search.c         |  3 +--
 src/compiler/nir/nir_search.h         |  3 +--
 src/compiler/nir/nir_search_helpers.h | 22 ++++++++++------------
 3 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/src/compiler/nir/nir_search.c b/src/compiler/nir/nir_search.c
index 7a84b18..cc17642 100644
--- a/src/compiler/nir/nir_search.c
+++ b/src/compiler/nir/nir_search.c
@@ -155,8 +155,7 @@ match_value(const nir_search_value *value, nir_alu_instr *instr, unsigned src,
              instr->src[src].src.ssa->parent_instr->type != nir_instr_type_load_const)
             return false;
 
-         if (var->cond && !var->cond(instr, src, num_components,
-                                     instr->src[src].swizzle))
+         if (var->cond && !var->cond(instr, src, num_components))
             return false;
 
          if (var->type != nir_type_invalid &&
diff --git a/src/compiler/nir/nir_search.h b/src/compiler/nir/nir_search.h
index dec19d5..357509a 100644
--- a/src/compiler/nir/nir_search.h
+++ b/src/compiler/nir/nir_search.h
@@ -76,8 +76,7 @@ typedef struct {
     * variables to require, for example, power-of-two in order for the search
     * to match.
     */
-   bool (*cond)(nir_alu_instr *instr, unsigned src,
-                unsigned num_components, const uint8_t *swizzle);
+   bool (*cond)(nir_alu_instr *instr, unsigned src, unsigned num_components);
 } nir_search_variable;
 
 typedef struct {
diff --git a/src/compiler/nir/nir_search_helpers.h b/src/compiler/nir/nir_search_helpers.h
index 20fdae6..59b7a0a 100644
--- a/src/compiler/nir/nir_search_helpers.h
+++ b/src/compiler/nir/nir_search_helpers.h
@@ -36,8 +36,7 @@ __is_power_of_two(unsigned int x)
 }
 
 static inline bool
-is_pos_power_of_two(nir_alu_instr *instr, unsigned src, unsigned num_components,
-                    const uint8_t *swizzle)
+is_pos_power_of_two(nir_alu_instr *instr, unsigned src, unsigned num_components)
 {
    nir_const_value *val = nir_src_as_const_value(instr->src[src].src);
 
@@ -48,13 +47,13 @@ is_pos_power_of_two(nir_alu_instr *instr, unsigned src, unsigned num_components,
    for (unsigned i = 0; i < num_components; i++) {
       switch (nir_op_infos[instr->op].input_types[src]) {
       case nir_type_int:
-         if (val->i32[swizzle[i]] < 0)
+         if (val->i32[instr->src[src].swizzle[i]] < 0)
             return false;
-         if (!__is_power_of_two(val->i32[swizzle[i]]))
+         if (!__is_power_of_two(val->i32[instr->src[src].swizzle[i]]))
             return false;
          break;
       case nir_type_uint:
-         if (!__is_power_of_two(val->u32[swizzle[i]]))
+         if (!__is_power_of_two(val->u32[instr->src[src].swizzle[i]]))
             return false;
          break;
       default:
@@ -66,8 +65,7 @@ is_pos_power_of_two(nir_alu_instr *instr, unsigned src, unsigned num_components,
 }
 
 static inline bool
-is_neg_power_of_two(nir_alu_instr *instr, unsigned src, unsigned num_components,
-                    const uint8_t *swizzle)
+is_neg_power_of_two(nir_alu_instr *instr, unsigned src, unsigned num_components)
 {
    nir_const_value *val = nir_src_as_const_value(instr->src[src].src);
 
@@ -78,9 +76,9 @@ is_neg_power_of_two(nir_alu_instr *instr, unsigned src, unsigned num_components,
    for (unsigned i = 0; i < num_components; i++) {
       switch (nir_op_infos[instr->op].input_types[src]) {
       case nir_type_int:
-         if (val->i32[swizzle[i]] > 0)
+         if (val->i32[instr->src[src].swizzle[i]] > 0)
             return false;
-         if (!__is_power_of_two(abs(val->i32[swizzle[i]])))
+         if (!__is_power_of_two(abs(val->i32[instr->src[src].swizzle[i]])))
             return false;
          break;
       default:
@@ -92,8 +90,7 @@ is_neg_power_of_two(nir_alu_instr *instr, unsigned src, unsigned num_components,
 }
 
 static inline bool
-is_zero_to_one(nir_alu_instr *instr, unsigned src, unsigned num_components,
-               const uint8_t *swizzle)
+is_zero_to_one(nir_alu_instr *instr, unsigned src, unsigned num_components)
 {
    nir_const_value *val = nir_src_as_const_value(instr->src[src].src);
 
@@ -103,7 +100,8 @@ is_zero_to_one(nir_alu_instr *instr, unsigned src, unsigned num_components,
    for (unsigned i = 0; i < num_components; i++) {
       switch (nir_op_infos[instr->op].input_types[src]) {
       case nir_type_float:
-         if (val->f32[swizzle[i]] < 0.0f || val->f32[swizzle[i]] > 1.0f)
+         if (val->f32[instr->src[src].swizzle[i]] < 0.0f ||
+             val->f32[instr->src[src].swizzle[i]] > 1.0f)
             return false;
          break;
       default:
-- 
2.9.3



More information about the mesa-dev mailing list