From a1aa78cb45cee5ba6fa9ecf1266760cdbb51f5f3 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Sun, 19 Mar 2017 21:45:20 -0700 Subject: [PATCH] aubinator: Track the current field's starting dword offset. The iterator code already computed this value, then we stored it in the structure name, strtok'd it back out, and also manually computed it when printing dword headers. Just put the value in the struct and use it. Way simpler. Reviewed-by: Lionel Landwerlin --- src/intel/tools/aubinator.c | 35 +++++++++++++---------------------- src/intel/tools/decoder.c | 8 ++++---- src/intel/tools/decoder.h | 1 + 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/intel/tools/aubinator.c b/src/intel/tools/aubinator.c index 1f6a1fe4b1d..fc2efd3e46e 100644 --- a/src/intel/tools/aubinator.c +++ b/src/intel/tools/aubinator.c @@ -96,23 +96,14 @@ valid_offset(uint32_t offset) } static void -print_dword_val(struct gen_field_iterator *iter, uint64_t offset, - int *dword_num) +print_dword_header(struct gen_field_iterator *iter, uint64_t offset) { - struct gen_field *f; - - f = iter->group->fields[iter->i - 1]; - const int dword = f->start / 32; - - if (*dword_num != dword) { - fprintf(outfile, "0x%08"PRIx64": 0x%08x : Dword %d\n", - offset + 4 * dword, iter->p[dword], dword); - *dword_num = dword; - } + fprintf(outfile, "0x%08"PRIx64": 0x%08x : Dword %d\n", + offset + 4 * iter->dword, iter->p[iter->dword], iter->dword); } static char * -print_iterator_values(struct gen_field_iterator *iter, int *idx) +print_iterator_values(struct gen_field_iterator *iter) { char *token = NULL; if (strstr(iter->value, "struct") == NULL) { @@ -121,7 +112,6 @@ print_iterator_values(struct gen_field_iterator *iter, int *idx) token = strtok(iter->value, " "); if (token != NULL) { token = strtok(NULL, " "); - *idx = atoi(strtok(NULL, ">")); } else { token = NULL; } @@ -136,7 +126,7 @@ decode_group(struct gen_spec *spec, struct gen_group *strct, { struct gen_field_iterator iter; char *token = NULL; - int idx = 0, dword_num = 0; + int last_dword = 0; uint64_t offset = 0; if (option_print_offsets) @@ -147,15 +137,16 @@ decode_group(struct gen_spec *spec, struct gen_group *strct, gen_field_iterator_init(&iter, strct, p, option_color == COLOR_ALWAYS); while (gen_field_iterator_next(&iter)) { - idx = 0; - print_dword_val(&iter, offset, &dword_num); - if (dword_num >= starting_dword) - token = print_iterator_values(&iter, &idx); + if (last_dword != iter.dword) { + print_dword_header(&iter, offset); + last_dword = iter.dword; + } + if (iter.dword >= starting_dword) + token = print_iterator_values(&iter); if (token != NULL) { - fprintf(outfile, "0x%08"PRIx64": 0x%08x : Dword %d\n", - offset + 4 * idx, p[idx], idx); + print_dword_header(&iter, offset); struct gen_group *struct_val = gen_spec_find_struct(spec, token); - decode_group(spec, struct_val, &p[idx], 0); + decode_group(spec, struct_val, &p[iter.dword], 0); token = NULL; } } diff --git a/src/intel/tools/decoder.c b/src/intel/tools/decoder.c index ec94ae4d92a..8838eb2500c 100644 --- a/src/intel/tools/decoder.c +++ b/src/intel/tools/decoder.c @@ -752,12 +752,12 @@ gen_field_iterator_next(struct gen_field_iterator *iter) f = iter->group->fields[iter->i++]; iter->name = f->name; - int index = f->start / 32; + iter->dword = f->start / 32; if ((f->end - f->start) > 32) - v.qw = ((uint64_t) iter->p[index+1] << 32) | iter->p[index]; + v.qw = ((uint64_t) iter->p[iter->dword+1] << 32) | iter->p[iter->dword]; else - v.qw = iter->p[index]; + v.qw = iter->p[iter->dword]; const char *enum_name = NULL; @@ -794,7 +794,7 @@ gen_field_iterator_next(struct gen_field_iterator *iter) break; case GEN_TYPE_STRUCT: snprintf(iter->value, sizeof(iter->value), - "", f->type.gen_struct->name, (f->start / 32)); + "", f->type.gen_struct->name, iter->dword); break; case GEN_TYPE_UFIXED: snprintf(iter->value, sizeof(iter->value), diff --git a/src/intel/tools/decoder.h b/src/intel/tools/decoder.h index 7b14ef4a647..700ce21f033 100644 --- a/src/intel/tools/decoder.h +++ b/src/intel/tools/decoder.h @@ -55,6 +55,7 @@ struct gen_field_iterator { const char *name; char value[128]; const uint32_t *p; + int dword; /**< current field starts at &p[dword] */ int i; bool print_colors; }; -- 2.30.2