intel/decoder: Clean up field iteration and fix sub-dword fields
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 24 Aug 2018 20:23:04 +0000 (15:23 -0500)
committerJason Ekstrand <jason.ekstrand@intel.com>
Sat, 25 Aug 2018 12:50:36 +0000 (07:50 -0500)
First of all, setting iter->name in advance_field is unnecessary because
it gets set by gen_decode_field which gets called immediately after
gen_decode_field in the one call-site.  Second, we weren't properly
initializing start_bit and end_bit in the initial condition of
gen_field_iterator_next so the first field of a struct would get printed
wrong if it doesn't start on the first bit.  This is fixed by adding a
iter_start_field helper which sets the field and also sets up the other
bits we need.  This fixes decoding of 3DSTATE_SBE_SWIZ.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
src/intel/common/gen_decoder.c

index 39da3cadbf8df655e74b08b7602d642e62afc630..e9dabeae6532f85440f3f8ed8f515bf222e86650 100644 (file)
@@ -812,6 +812,18 @@ iter_more_groups(const struct gen_field_iterator *iter)
    }
 }
 
+static void
+iter_start_field(struct gen_field_iterator *iter, struct gen_field *field)
+{
+   iter->field = field;
+
+   int group_member_offset = iter_group_offset_bits(iter, iter->group_iter);
+
+   iter->start_bit = group_member_offset + iter->field->start;
+   iter->end_bit = group_member_offset + iter->field->end;
+   iter->struct_desc = NULL;
+}
+
 static void
 iter_advance_group(struct gen_field_iterator *iter)
 {
@@ -826,32 +838,20 @@ iter_advance_group(struct gen_field_iterator *iter)
       }
    }
 
-   iter->field = iter->group->fields;
+   iter_start_field(iter, iter->group->fields);
 }
 
 static bool
 iter_advance_field(struct gen_field_iterator *iter)
 {
    if (iter_more_fields(iter)) {
-      iter->field = iter->field->next;
+      iter_start_field(iter, iter->field->next);
    } else {
       if (!iter_more_groups(iter))
          return false;
 
       iter_advance_group(iter);
    }
-
-   if (iter->field->name)
-      snprintf(iter->name, sizeof(iter->name), "%s", iter->field->name);
-   else
-      memset(iter->name, 0, sizeof(iter->name));
-
-   int group_member_offset = iter_group_offset_bits(iter, iter->group_iter);
-
-   iter->start_bit = group_member_offset + iter->field->start;
-   iter->end_bit = group_member_offset + iter->field->end;
-   iter->struct_desc = NULL;
-
    return true;
 }
 
@@ -1006,9 +1006,9 @@ gen_field_iterator_next(struct gen_field_iterator *iter)
    /* Initial condition */
    if (!iter->field) {
       if (iter->group->fields)
-         iter->field = iter->group->fields;
+         iter_start_field(iter, iter->group->fields);
       else
-         iter->field = iter->group->next->fields;
+         iter_start_field(iter, iter->group->next->fields);
 
       bool result = iter_decode_field(iter);
       if (iter->p_end)