<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 15, 2016 at 12:41 AM, Iago Toral <span dir="ltr"><<a href="mailto:itoral@igalia.com" target="_blank">itoral@igalia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Mon, 2016-03-14 at 17:33 -0700, Jason Ekstrand wrote:<br>
><br>
><br>
> On Mon, Mar 7, 2016 at 12:46 AM, Samuel Iglesias Gonsálvez<br>
> <<a href="mailto:siglesias@igalia.com">siglesias@igalia.com</a>> wrote:<br>
>         From: Connor Abbott <<a href="mailto:connor.w.abbott@intel.com">connor.w.abbott@intel.com</a>><br>
><br>
>         When we replace an expresion we have to compute bitsize<br>
>         information for the<br>
>         replacement. We do this in two passes to validate that bitsize<br>
>         information<br>
>         is consistent and correct: first we propagate bitsize from<br>
>         child nodes to<br>
>         parent, then we do it the other way around, starting from the<br>
>         original's<br>
>         instruction destination bitsize.<br>
><br>
>         v2 (Iago):<br>
>         - Always use nir_type_bool32 instead of nir_type_bool when<br>
>         generating<br>
>           algebraic optimizations. Before we used nir_type_bool32 with<br>
>         constants<br>
>           and nir_type_bool with variables.<br>
>         - Fix bool comparisons in nir_search.c to account for bitsized<br>
>         types.<br>
><br>
>         v3 (Sam):<br>
>         - Unpack the double constant value as unsigned long long (8<br>
>         bytes) in<br>
>         nir_algrebraic.py.<br>
><br>
>         Signed-off-by: Iago Toral Quiroga <<a href="mailto:itoral@igalia.com">itoral@igalia.com</a>><br>
>         Signed-off-by: Samuel Iglesias Gonsálvez<br>
>         <<a href="mailto:siglesias@igalia.com">siglesias@igalia.com</a>><br>
>         ---<br>
>          src/compiler/nir/nir_algebraic.py |  22 +++-<br>
>          src/compiler/nir/nir_search.c     | 244<br>
>         ++++++++++++++++++++++++++++++++++----<br>
>          src/compiler/nir/nir_search.h     |   8 +-<br>
>          3 files changed, 247 insertions(+), 27 deletions(-)<br>
><br>
>         diff --git a/src/compiler/nir/nir_algebraic.py<br>
>         b/src/compiler/nir/nir_algebraic.py<br>
>         index 2357b57..1818877 100644<br>
>         --- a/src/compiler/nir/nir_algebraic.py<br>
>         +++ b/src/compiler/nir/nir_algebraic.py<br>
>         @@ -63,11 +63,11 @@ class Value(object):<br>
>          static const ${val.c_type} ${<a href="http://val.name" rel="noreferrer" target="_blank">val.name</a>} = {<br>
>             { ${val.type_enum} },<br>
>          % if isinstance(val, Constant):<br>
>         -   { ${hex(val)} /* ${val.value} */ },<br>
>         +   ${val.type()}, { ${hex(val)} /* ${val.value} */ },<br>
>          % elif isinstance(val, Variable):<br>
>             ${val.index}, /* ${val.var_name} */<br>
>             ${'true' if val.is_constant else 'false'},<br>
>         -   nir_type_${ val.required_type or 'invalid' },<br>
>         +   ${val.type() or 'nir_type_invalid' },<br>
>          % elif isinstance(val, Expression):<br>
>             nir_op_${val.opcode},<br>
>             { ${', '.join(src.c_ptr for src in val.sources)} },<br>
>         @@ -107,10 +107,18 @@ class Constant(Value):<br>
>                if isinstance(self.value, (int, long)):<br>
>                   return hex(self.value)<br>
>                elif isinstance(self.value, float):<br>
>         -         return hex(struct.unpack('I', struct.pack('f',<br>
>         self.value))[0])<br>
>         +         return hex(struct.unpack('Q', struct.pack('d',<br>
>         self.value))[0])<br>
>                else:<br>
>                   assert False<br>
><br>
>         +   def type(self):<br>
>         +      if isinstance(self.value, (bool)):<br>
>         +         return "nir_type_bool32"<br>
>         +      elif isinstance(self.value, (int, long)):<br>
>         +         return "nir_type_int"<br>
>         +      elif isinstance(self.value, float):<br>
>         +         return "nir_type_float"<br>
>         +<br>
>          _var_name_re = re.compile(r"(?P<const>#)?(?P<name>\w<br>
>         +)(?:@(?P<type>\w+))?")<br>
><br>
>          class Variable(Value):<br>
>         @@ -129,6 +137,14 @@ class Variable(Value):<br>
><br>
>                self.index = varset[self.var_name]<br>
><br>
>         +   def type(self):<br>
>         +      if self.required_type == 'bool':<br>
>         +         return "nir_type_bool32"<br>
>         +      elif self.required_type in ('int', 'unsigned'):<br>
>         +         return "nir_type_int"<br>
>         +      elif self.required_type == 'float':<br>
>         +         return "nir_type_float"<br>
>         +<br>
>          class Expression(Value):<br>
>             def __init__(self, expr, name_base, varset):<br>
>                Value.__init__(self, name_base, "expression")<br>
>         diff --git a/src/compiler/nir/nir_search.c<br>
>         b/src/compiler/nir/nir_search.c<br>
>         index f509ce6..e874c79 100644<br>
>         --- a/src/compiler/nir/nir_search.c<br>
>         +++ b/src/compiler/nir/nir_search.c<br>
>         @@ -62,7 +62,8 @@ alu_instr_is_bool(nir_alu_instr *instr)<br>
>             case nir_op_inot:<br>
>                return src_is_bool(instr->src[0].src);<br>
>             default:<br>
>         -      return nir_op_infos[instr->op].output_type ==<br>
>         nir_type_bool;<br>
>         +      return (nir_op_infos[instr->op].output_type &<br>
>         NIR_ALU_TYPE_BASE_TYPE_MASK)<br>
>         +             == nir_type_bool;<br>
>             }<br>
>          }<br>
><br>
>         @@ -125,8 +126,10 @@ match_value(const nir_search_value<br>
>         *value, nir_alu_instr *instr, unsigned src,<br>
>                      nir_alu_instr *src_alu =<br>
><br>
>         nir_instr_as_alu(instr->src[src].src.ssa->parent_instr);<br>
><br>
>         -            if (nir_op_infos[src_alu->op].output_type !=<br>
>         var->type &&<br>
>         -                !(var->type == nir_type_bool &&<br>
>         alu_instr_is_bool(src_alu)))<br>
>         +            if ((nir_op_infos[src_alu->op].output_type &<br>
>         +                 NIR_ALU_TYPE_BASE_TYPE_MASK) != var->type &&<br>
>         +                !((var->type & NIR_ALU_TYPE_BASE_TYPE_MASK)<br>
>         == nir_type_bool &&<br>
>         +                  alu_instr_is_bool(src_alu)))<br>
>                         return false;<br>
>                   }<br>
><br>
>         @@ -158,21 +161,65 @@ match_value(const nir_search_value<br>
>         *value, nir_alu_instr *instr, unsigned src,<br>
>                nir_load_const_instr *load =<br>
><br>
>         nir_instr_as_load_const(instr->src[src].src.ssa->parent_instr);<br>
><br>
>         -      switch (nir_op_infos[instr->op].input_types[src]) {<br>
>         +      switch (const_val->type) {<br>
>                case nir_type_float:<br>
>                   for (unsigned i = 0; i < num_components; ++i) {<br>
>         -            if (load->value.f[new_swizzle[i]] !=<br>
>         const_val->data.f)<br>
>         +            double val;<br>
>         +            switch (load->def.bit_size) {<br>
>         +            case 32:<br>
>         +               val = load->value.f[new_swizzle[i]];<br>
>         +               break;<br>
>         +            case 64:<br>
>         +               val = load->value.d[new_swizzle[i]];<br>
>         +               break;<br>
>         +            default:<br>
>         +               unreachable("unknown bit size");<br>
>         +            }<br>
>         +<br>
>         +            if (val != const_val->data.d)<br>
>                         return false;<br>
>                   }<br>
>                   return true;<br>
>         +<br>
>                case nir_type_int:<br>
>         +         for (unsigned i = 0; i < num_components; ++i) {<br>
>         +            int64_t val;<br>
>         +            switch (load->def.bit_size) {<br>
>         +            case 32:<br>
>         +               val = load->value.i[new_swizzle[i]];<br>
>         +               break;<br>
>         +            case 64:<br>
>         +               val = load->value.l[new_swizzle[i]];<br>
>         +               break;<br>
>         +            default:<br>
>         +               unreachable("unknown bit size");<br>
>         +            }<br>
>         +<br>
>         +            if (val != const_val->data.i)<br>
>         +               return false;<br>
>         +         }<br>
>         +         return true;<br>
>         +<br>
>                case nir_type_uint:<br>
>         -      case nir_type_bool:<br>
>         +      case nir_type_bool32:<br>
>                   for (unsigned i = 0; i < num_components; ++i) {<br>
>         -            if (load->value.i[new_swizzle[i]] !=<br>
>         const_val->data.i)<br>
>         +            uint64_t val;<br>
>         +            switch (load->def.bit_size) {<br>
>         +            case 32:<br>
>         +               val = load->value.u[new_swizzle[i]];<br>
>         +               break;<br>
>         +            case 64:<br>
>         +               val = load->value.ul[new_swizzle[i]];<br>
>         +               break;<br>
>         +            default:<br>
>         +               unreachable("unknown bit size");<br>
>         +            }<br>
>         +<br>
>         +            if (val != const_val->data.u)<br>
>                         return false;<br>
><br>
><br>
> 64-bit.  Also, we may want bool to be its own case.  I think keeping<br>
> it with uint is probably fine.<br>
<br>
</div></div>Actually, const_val->data.u is 64-bit (and the same for<br>
const_val->data.i in the case above). The definition is a bit later in<br>
this same patch:<br></blockquote><div><br></div><div>Right.  I think this was actually a stray comment.  I meant to take it out after I'd read through the whole patch.  I think it's fine as-is.  No need for explicit bit sizes if it's all 64-bit all the time.<br></div><div>--Jason<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
(...)<br>
<span class="">>         diff --git a/src/compiler/nir/nir_search.h<br>
>         b/src/compiler/nir/nir_search.h<br>
>         index 7d47792..321d6d0 100644<br>
>         --- a/src/compiler/nir/nir_search.h<br>
>         +++ b/src/compiler/nir/nir_search.h<br>
>         @@ -71,10 +71,12 @@ typedef struct {<br>
>          typedef struct {<br>
>             nir_search_value value;<br>
><br>
>         +   nir_alu_type type;<br>
>         +<br>
>             union {<br>
>         -      uint32_t u;<br>
>         -      int32_t i;<br>
>         -      float f;<br>
>         +      uint64_t u;<br>
>         +      int64_t i;<br>
>         +      double d;<br>
>             } data;<br>
>          } nir_search_constant;<br>
<br>
</span>Maybe we should rename these to u64, i64 as f64 like you suggested for a<br>
similar case in another patch?<br>
<br>
<br>
</blockquote></div><br></div></div>