sim: ppc: collapse is_readonly & length switch tables heavily

Since we know we'll return 0 by default, we don't have to output case
statements for readonly or length fields whose values are also zero.
This is the most common case by far and thus generates a much smaller
switch table in the end.
This commit is contained in:
Mike Frysinger
2022-11-10 02:24:41 +07:00
parent 1eff12f75a
commit 40466c48e8

View File

@ -238,14 +238,22 @@ gen_spreg_c(spreg_table *table, lf *file)
spreg_table_entry *entry;
lf_printf(file, " switch (spr) {\n");
for (entry = table->sprs; entry != NULL; entry = entry->next) {
if (strcmp(*attribute, "is_valid") == 0) {
lf_printf(file, " case %d:\n", entry->spreg_nr);
if (strcmp(*attribute, "is_valid") == 0)
/* No return -- see below. */;
else if (strcmp(*attribute, "is_readonly") == 0)
} else if (strcmp(*attribute, "is_readonly") == 0) {
/* Since we return 0 by default, only output non-zero entries. */
if (entry->is_readonly) {
lf_printf(file, " case %d:\n", entry->spreg_nr);
lf_printf(file, " return %d;\n", entry->is_readonly);
else if (strcmp(*attribute, "length") == 0)
}
} else if (strcmp(*attribute, "length") == 0) {
/* Since we return 0 by default, only output non-zero entries. */
if (entry->length) {
lf_printf(file, " case %d:\n", entry->spreg_nr);
lf_printf(file, " return %d;\n", entry->length);
else
}
} else
ASSERT(0);
}
/* Output a single return for is_valid. */