<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Tue, Jan 15, 2019 at 7:54 AM Iago Toral Quiroga <<a href="mailto:itoral@igalia.com">itoral@igalia.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">We open coded this in a couple of places, so a helper function is probably<br>
sensible. Plus it makes it more consistent with the 3src hardware type case.<br>
<br>
Suggested-by: Topi Pohjolainen <<a href="mailto:topi.pohjolainen@intel.com" target="_blank">topi.pohjolainen@intel.com</a>><br>
---<br>
 src/intel/compiler/brw_reg_type.c | 34 ++++++++++++++++---------------<br>
 1 file changed, 18 insertions(+), 16 deletions(-)<br>
<br>
diff --git a/src/intel/compiler/brw_reg_type.c b/src/intel/compiler/brw_reg_type.c<br>
index 09b3ea61d4c..0c9f522eca0 100644<br>
--- a/src/intel/compiler/brw_reg_type.c<br>
+++ b/src/intel/compiler/brw_reg_type.c<br>
@@ -193,6 +193,20 @@ static const struct hw_3src_type {<br>
 #undef E<br>
 };<br>
<br>
+static inline const struct hw_type *<br>
+get_hw_type_map(const struct gen_device_info *devinfo, uint32_t *size)<br>
+{<br>
+   if (devinfo->gen >= 11) {<br>
+      if (size)<br>
+         *size = ARRAY_SIZE(gen11_hw_type);<br></blockquote><div><br></div><div>All of these type tables have the same size because we declare everything through BRW_REGISTER_TYPE_LAST.  Do we really need to be returning the array size separately for every table?<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">
+      return gen11_hw_type;<br>
+   } else {<br>
+      if (size)<br>
+         *size = ARRAY_SIZE(gen4_hw_type);<br>
+      return gen4_hw_type;<br>
+   }<br>
+}<br>
+<br>
 /**<br>
  * Convert a brw_reg_type enumeration value into the hardware representation.<br>
  *<br>
@@ -203,16 +217,10 @@ brw_reg_type_to_hw_type(const struct gen_device_info *devinfo,<br>
                         enum brw_reg_file file,<br>
                         enum brw_reg_type type)<br>
 {<br>
-   const struct hw_type *table;<br>
-<br>
-   if (devinfo->gen >= 11) {<br>
-      assert(type < ARRAY_SIZE(gen11_hw_type));<br>
-      table = gen11_hw_type;<br>
-   } else {<br>
-      assert(type < ARRAY_SIZE(gen4_hw_type));<br>
-      table = gen4_hw_type;<br>
-   }<br>
+   uint32_t table_size;<br>
+   const struct hw_type *table = get_hw_type_map(devinfo, &table_size);<br>
<br>
+   assert(type < table_size);<br>
    assert(devinfo->has_64bit_types || brw_reg_type_to_size(type) < 8 ||<br>
           type == BRW_REGISTER_TYPE_NF);<br>
<br>
@@ -234,13 +242,7 @@ enum brw_reg_type<br>
 brw_hw_type_to_reg_type(const struct gen_device_info *devinfo,<br>
                         enum brw_reg_file file, unsigned hw_type)<br>
 {<br>
-   const struct hw_type *table;<br>
-<br>
-   if (devinfo->gen >= 11) {<br>
-      table = gen11_hw_type;<br>
-   } else {<br>
-      table = gen4_hw_type;<br>
-   }<br>
+   const struct hw_type *table = get_hw_type_map(devinfo, NULL);<br>
<br>
    if (file == BRW_IMMEDIATE_VALUE) {<br>
       for (enum brw_reg_type i = 0; i <= BRW_REGISTER_TYPE_LAST; i++) {<br>
-- <br>
2.17.1<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">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/mailman/listinfo/mesa-dev</a><br>
</blockquote></div></div>