<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Oct 12, 2017 at 11:38 AM, Jose Maria Casanova Crespo <span dir="ltr"><<a href="mailto:jmcasanova@igalia.com" target="_blank">jmcasanova@igalia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">From: Alejandro Piñeiro <<a href="mailto:apinheiro@igalia.com">apinheiro@igalia.com</a>><br>
<br>
Returns the brw_type for a given ssa.bit_size, and a reference type.<br>
So if bit_size is 64, and the reference type is BRW_REGISTER_TYPE_F,<br>
it returns BRW_REGISTER_TYPE_DF. The same applies if bit_size is 32<br>
and reference type is BRW_REGISTER_TYPE_HF it returns BRW_REGISTER_TYPE_F<br>
<br>
v2 (Jason Ekstrand):<br>
 - Use better unreachable() messages<br>
 - Add Q types<br>
<br>
Signed-off-by: Jose Maria Casanova Crespo <<a href="mailto:jmcasanova@igalia.com">jmcasanova@igalia.com</a>><br>
Signed-off-by: Alejandro Piñeiro <<a href="mailto:apinheiro@igalia.com">apinheiro@igalia.com</a><br>
Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br>
---<br>
 src/intel/compiler/brw_fs_nir.<wbr>cpp | 69 ++++++++++++++++++++++++++++++<wbr>++++++---<br>
 1 file changed, 64 insertions(+), 5 deletions(-)<br>
<br>
diff --git a/src/intel/compiler/brw_fs_<wbr>nir.cpp b/src/intel/compiler/brw_fs_<wbr>nir.cpp<br>
index 7ed44f534c..affe65d5e9 100644<br>
--- a/src/intel/compiler/brw_fs_<wbr>nir.cpp<br>
+++ b/src/intel/compiler/brw_fs_<wbr>nir.cpp<br>
@@ -227,6 +227,65 @@ fs_visitor::nir_emit_system_<wbr>values()<br>
    }<br>
 }<br>
<br>
+/*<br>
+ * Returns a type based on a reference_type (word, float, half-float) and a<br>
+ * given bit_size.<br>
+ *<br>
+ * Reference BRW_REGISTER_TYPE are HF,F,DF,W,D,UW,UD.<br>
+ *<br>
+ * @FIXME: 64-bit return types are always DF on integer types to maintain<br>
+ * compability with uses of DF previously to the introduction of int64<br>
+ * support.<br>
+ */<br>
+static brw_reg_type<br>
+brw_reg_type_from_bit_size(<wbr>const unsigned bit_size,<br>
+                           const brw_reg_type reference_type)<br>
+{<br>
+   switch(reference_type) {<br>
+   case BRW_REGISTER_TYPE_HF:<br>
+   case BRW_REGISTER_TYPE_F:<br>
+   case BRW_REGISTER_TYPE_DF:<br>
+      switch(bit_size) {<br>
+      case 16:<br>
+         return BRW_REGISTER_TYPE_HF;<br>
+      case 32:<br>
+         return BRW_REGISTER_TYPE_F;<br>
+      case 64:<br>
+         return BRW_REGISTER_TYPE_DF;<br>
+      default:<br>
+         unreachable("Invalid bit size");<br>
+      }<br>
+   case BRW_REGISTER_TYPE_W:<br>
+   case BRW_REGISTER_TYPE_D:<br>
+   case BRW_REGISTER_TYPE_Q:<br>
+      switch(bit_size) {<br>
+      case 16:<br>
+         return BRW_REGISTER_TYPE_W;<br>
+      case 32:<br>
+         return BRW_REGISTER_TYPE_D;<br>
+      case 64:<br>
+         return BRW_REGISTER_TYPE_DF;<br></blockquote><div><br></div><div>This should be BRW_REGISTER_TYPE_Q<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+      default:<br>
+         unreachable("Invalid bit size");<br>
+      }<br>
+   case BRW_REGISTER_TYPE_UW:<br>
+   case BRW_REGISTER_TYPE_UD:<br>
+   case BRW_REGISTER_TYPE_UQ:<br>
+      switch(bit_size) {<br>
+      case 16:<br>
+         return BRW_REGISTER_TYPE_UW;<br>
+      case 32:<br>
+         return BRW_REGISTER_TYPE_UD;<br>
+      case 64:<br>
+         return BRW_REGISTER_TYPE_DF;<br></blockquote><div><br></div><div>This should be BRW_REGISTER_TYPE_UQ</div><div><br></div><div>With those fixed,</div><div><br></div><div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+      default:<br>
+         unreachable("Invalid bit size");<br>
+      }<br>
+   default:<br>
+      unreachable("Unknown type");<br>
+   }<br>
+}<br>
+<br>
 void<br>
 fs_visitor::nir_emit_impl(nir_<wbr>function_impl *impl)<br>
 {<br>
@@ -240,7 +299,7 @@ fs_visitor::nir_emit_impl(nir_<wbr>function_impl *impl)<br>
          reg->num_array_elems == 0 ? 1 : reg->num_array_elems;<br>
       unsigned size = array_elems * reg->num_components;<br>
       const brw_reg_type reg_type =<br>
-         reg->bit_size == 32 ? BRW_REGISTER_TYPE_F : BRW_REGISTER_TYPE_DF;<br>
+         brw_reg_type_from_bit_size(<wbr>reg->bit_size, BRW_REGISTER_TYPE_F);<br>
       nir_locals[reg->index] = bld.vgrf(reg_type, size);<br>
    }<br>
<br>
@@ -1341,7 +1400,7 @@ fs_visitor::nir_emit_load_<wbr>const(const fs_builder &bld,<br>
                                 nir_load_const_instr *instr)<br>
 {<br>
    const brw_reg_type reg_type =<br>
-      instr->def.bit_size == 32 ? BRW_REGISTER_TYPE_D : BRW_REGISTER_TYPE_DF;<br>
+      brw_reg_type_from_bit_size(<wbr>instr->def.bit_size, BRW_REGISTER_TYPE_D);<br>
    fs_reg reg = bld.vgrf(reg_type, instr->def.num_components);<br>
<br>
    switch (instr->def.bit_size) {<br>
@@ -1369,8 +1428,8 @@ fs_visitor::get_nir_src(const nir_src &src)<br>
    fs_reg reg;<br>
    if (src.is_ssa) {<br>
       if (src.ssa->parent_instr->type == nir_instr_type_ssa_undef) {<br>
-         const brw_reg_type reg_type = src.ssa->bit_size == 32 ?<br>
-            BRW_REGISTER_TYPE_D : BRW_REGISTER_TYPE_DF;<br>
+         const brw_reg_type reg_type =<br>
+            brw_reg_type_from_bit_size(<wbr>src.ssa->bit_size, BRW_REGISTER_TYPE_D);<br>
          reg = bld.vgrf(reg_type, src.ssa->num_components);<br>
       } else {<br>
          reg = nir_ssa_values[src.ssa->index]<wbr>;<br>
@@ -1404,7 +1463,7 @@ fs_visitor::get_nir_dest(const nir_dest &dest)<br>
 {<br>
    if (dest.is_ssa) {<br>
       const brw_reg_type reg_type =<br>
-         dest.ssa.bit_size == 32 ? BRW_REGISTER_TYPE_F : BRW_REGISTER_TYPE_DF;<br>
+         brw_reg_type_from_bit_size(<wbr>dest.ssa.bit_size, BRW_REGISTER_TYPE_F);<br>
       nir_ssa_values[dest.ssa.index] =<br>
          bld.vgrf(reg_type, dest.ssa.num_components);<br>
       return nir_ssa_values[dest.ssa.index]<wbr>;<br>
<span class="gmail-HOEnZb"><font color="#888888">--<br>
2.13.6<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>